CommandBus | package provides an opinionated base
kandi X-RAY | CommandBus Summary
kandi X-RAY | CommandBus Summary
This package provides an opinionated base to get started using the Command Bus architecture in PHP. Most of what's here has been derived from code and discussions with @ShawnMcCool. The structure may not fit with everyone's definitions of how a Command Bus should be implemented, however it provides a path of little resistance for newcomers.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Register the command bus .
- Add a new book .
- Validate the request .
- Log a request
- Extract request data
- Execute a Request
- Handle validation errors .
- Get the handler .
- Get the handler class for the request
- Returns the validator class name .
CommandBus Key Features
CommandBus Examples and Code Snippets
Community Discussions
Trending Discussions on CommandBus
QUESTION
Hello I am trying to start studying about es, microservices and then I would like to know about the command bus I basically believe that his responsibility is just to execute the command handler? does it necessarily have to be a queue? can you make kafka as a command bus or redis? I have a simple command bus implementation, but I would like to implement a command bus to be used the same command bus for 3 microservices, the way I did I would have to have a command bus for each ms, and register the commands and the commands handlers for each micro service
impl with typescript :
...ANSWER
Answered 2021-Apr-28 at 08:05You typically don't need a command-bus/queue, instead send the commands from the user/client directly to the Commandhandler/aggregate.
Kafka is better suited for event-driven architectures, where various services post events representing thins that happened and then for other services to consume.
Also, CQRS/EventSourcing are patterns you apply within one service (bounded context) and not across multiple services. You can use events to communicate between services, but this a separate thing, just like what this picture tries to show:
Events on the inside is not the same as events on the outside
QUESTION
Hello I have a command bus, a query bus, which basically has a keypair with the name of the command or query and the handler and then I execute the command that should publish my event. But I have some doubts about how I could do my event-bus. is the command-bus part of an event-bus? how could I do an event-bus with the handlers
command-bus:
...ANSWER
Answered 2021-Mar-24 at 13:47I see there's some confusion between the various Buses and the Event Store. Before attempting to implement an Event Bus, you need to answer one important question that lies at the foundation of any Event Sourcing implementation:
- How to preserve the Event Store as the Single Source of Truth?
That is, your Event Store contains the complete state of the domain. This also means that the consumers of the Event Bus (whatever it ends up being - a message queue, a streaming platform, Redis, etc.) should only get the events that are persisted. Therefore, the goals become:
- Only deliver events on the Bus that are persisted to the Store (so if you get an error writing to the Store, or maybe a Concurrency Exception, do not deliver via bus!)
- Deliver all events to all interested consumers, without losing any events
These two goals intuitively translate to "I want atomic commit between the Event Store and the Event Bus". This is simplest to achieve when they're the same thing!
So, instead of thinking about how to connect an "Event Bus" to command handlers and send events back and forth, think about how to retrieve already persisted events from the Event Store and subscribe to that. This also removes any dependency between command handlers and event subscribers - they live on different sides of the Event Store (writer vs. reader), and could be in different processes, on different machines.
QUESTION
I'm trying to integrate my nestjs application's cqrs setup with a external message service such as Redis. I've found a pull request and a comment on the nestJS github stating that I should be able to integrate my query/event/command bus with external services since version 7.0 of cqrs.
I've been trying to implement this, but I can't find much information from nestjs on the subject. The only thing I could find was an outdated configuration example and an open topic on github for creating tutorials on how to implement this. I managed to replace the default publisher and subscriper by going off the limited help I could find on github about this topic, but I don't really understand how I can use that to connect to the external service or if this is the best approach for this problem.
EventBus
...ANSWER
Answered 2020-Nov-17 at 15:28So after a couple days I managed to find two approaches to connecting to an external eventbus. I found out that I don't really need an external command or query bus as these come in through API calls. So if you want to connect to an external eventbus with NestJS here are the two options I found:
- Via a custom publisher & subscriber
- Via the NestJS Microservice package
The two approaches mainly differ in the way they connect to the external eventbus and how they handle incoming messages. Depending on your needs one might suit you better than the other, but I went with the first option.
Custom publisher & subscriber
In my application I was already using manual publish calls to my eventbus by using the EventBus class from NestJS and calling .publish()
for my events. I created a service that wrapped around the local NestJS eventbus together with the custom publisher and custom subscriber.
eventBusService.ts
QUESTION
Lately I have some issues with Autofac.
I have an aggregate service like this:
...ANSWER
Answered 2020-Oct-28 at 12:28The issue was Assembly scanning in .net core 3.1. The old - non working way:
QUESTION
I have been exploring Microservice Architecture, and even though the technologies I use are in Microsoft Domain, the question is generic.
I get the Idea of API Gateway esp for things like Authentication. The pattern I am roughly following is based on CQRS + Event Sourcing
Request-> Command ##CommandBus##->CommandHandler -> Change Aggregate State->Store Events-> PublishDomainEvents ->Publish Integration events ##Event Bus## -----> Update Read Models
Many times initial Command will be handled by ProcessManager (consumer) to Orchestrate workflow.
All Microservices Application Layer consume Command from Bus and work on changing Aggregate state. Once done, the Read model store is updated. Currently, there is only a single Read Database which is updated
When I started with Command Bus, The REST API per microservices were for mainly Get requests ( Read ), which would dip into the same Read Database as all other Services and rest for accepting Command from Gateway.
Based on my current Scenario, Is there a logic in having REST API's per Microservice? I know we can do Async with Rest API to push commands, but what is the point when I am already using a Bus.
But now I am thinking of not having API per Service but rather API's based on usage. It's then not limited to single Gateway but few Gateway API projects.
Are there any Cons/ pitfalls with this approach?
Edit 2-- **Trying to rephrase if it gives context ** My microservice structure is very similar (to what @mrdnk commented) . As you In I will introduce technology to make it more clear. I use Mass transit over RabbitMQ for inter service communication.
As of now I have API gateway used by client applications, which would then call appropriate microsservice API to push a command object. the API method itself acts as a Command Handler (acting as Application layer) calls Aggregate and make it undergo changes. Domain Events based on the change are published within the process with Mediatr. Any events that outside (microservice) world needs to know is published on the bus. I started to look at the communication and said to myself why not use the Bus also for commands (as command bus). That way I can have more reselient and async process.
Application layer will listen to command and handle appropriately. This way I feel the service is more encapsulated. On API side (individual microservce) I dont need to expose any rest api for use by gateway. API in Gateway wil listen to request and create command object. this will be queued to bus. Consumer (command handler) on Microservice will consume Command and so on.
Currently all Writes are eventsourced (mongodb). Reads go to SQL Server. I can create API just for Queries from Read side. No more need to have Http API from Microservice at all.
I know technically it would work but Dont know if there are any pitfalls.
Regards, Mar
...ANSWER
Answered 2020-Aug-19 at 07:13I think it is a good idea to have Microservices communicate with each other asynchronously and in practice I also use this appraoch with a mix of orchestration and choreography depending on the use cases.
Concerning the public API which you expose to your clients (e.g. web clients) over the internet it really depends on the determining factors and the options you are given. If your clients require REST based communication I would recommend to provide a fast response to the client synchronously by just providing the information that it went through Ok and some kind of unique id.
So if you think of an order request of an online shop the API gateway would forward the request to the order Microservice (either via REST or in your case via Messaging and some translation from asynchronous to synchronous response at the API gateway layer). Anyway, there should be some kind of immediate response to the client the order service can provide which could simply contain the id of the new order. Everything else for processing the order will than happen asynchronously either completely via an event-based choreography (started by an OrderRequestReceived event or whatever name fits the domain language) or via some kind of workflow orchestrated by the order service (but still with asynchronous messaging).
The client can then always use the order id to query the current state of the order which you will than provide based on the read model you are building.
If you are free to implement the client the way want you can also look into WebSockets, using HTTP/2 to allow for pushing of status changes rather than requiring the clients to poll for the current state. Or you could even look into gRPC...
QUESTION
I'm using Axon 4.3 with JPA/Spring. I want to inject entityManager in my interceptor, so i used ContainerManagedEntityManagerProvider in my configuration. but i have this error when i run my application
...Description: Parameter 0 of method configureCommandBus in AxonConfig required a bean of type 'org.axonframework.springboot.util.jpa.ContainerManagedEntityManagerProvider' that could not be found.
Action: Consider defining a bean of type 'org.axonframework.springboot.util.jpa.ContainerManagedEntityManagerProvider' in your configuration.
ANSWER
Answered 2020-Aug-10 at 11:03The ContainerManagedEntityManagerProvider
instance created by Axon, if you are using the Spring Boot Starter, through the JpaAutoConfiguration
looks as follows:
QUESTION
Having the following class hierarchy in a Deno Typescript project:
AccountPutController.ts
...ANSWER
Answered 2020-Jul-06 at 14:15this
is determined when you're calling a function. How are you invoking your handle
method?
Consider this example:
QUESTION
Ok, so I'm trying to implement a simple "Command Bus" in TypeScript, but I'm tripping up over generics and I wonder if someone could help me. Here is my code:
This is the interface for the commandbus
...ANSWER
Answered 2020-Jun-28 at 17:20Generic functions in TypeScript act as a function representing every possible specification of its generic type parameters, since it's the caller of the function that specifies the type parameter, not the implementer:
QUESTION
I have a mediator which I have recently needed to synchronize one at a time message dispatch on a background thread but it is locking, demonstrated below.
I post a command to a queue and return a task from a TaskCompletionSource:
...ANSWER
Answered 2020-May-13 at 14:00The reason for the deadlock is rather simple:
- There is one code loop (not a specific thread; see below) that is responsible for processing the queue. As it processes each command, it
await
s that command's handler. - There is a command handler that
await
s another command to be handled. However, this cannot work because no further commands will be processed; the code loop will not dequeue the next command until this one completes.
Put another way, it is not logically possible for one command to execute another command if commands can only be executed one at a time.
There's a few possible approaches to solving this problem. I do not recommend the "re-entrant" approach; reentrancy is the cause of many subtle logic bugs. The approaches I would recommend are one of:
- Change the
Send
semantics so that they're a "queue" semantic. This means it's not possible to get command results; results would have to be sent as a message through some mediator. - Have the code loop not
await
the command handler, allowing it to loop back and pick up the next command. This means it doesn't "synchronize one at a time" any more. - Redefine "synchronize one at a time" to mean "one at a time but if it's
await
ing then it doesn't count as one". In that case, you can probably use something likeConcurrentExclusiveSchedulerPair
orNito.AsyncEx.AsyncContext
to run the method chunks one at a time.
Side note: LongRunning
doesn't do what you think it's doing. StartNew
is not async
-aware, so the LongRunning
flag only applies to the code up to the first await
; after that, the code in that lambda will run on arbitrary thread pool threads (without LongRunning
set). Replacing StartNew
with Task.Run
will make the code more clear.
QUESTION
PROBLEM:
RESEARCH: At https://gitlab.com/ZonZonZon/simple-axon.git I've made up a simple Axon-app to show that JAR-artifact built with Gradle-plugin com.github.johnrengelman.shadow
doesn't autoconfigure Axon beans when (when run as JAR). Though it runs fine under Intellij.
From project root in terminal:
...ANSWER
Answered 2020-Apr-21 at 11:53So, this took my some investigation to get a hunch what is going wrong, but I know what the problem is. Quick notice, it's not an Axon specific thing, rather the plugin you are using.
I ran your sample project and indeed ended up with the same result; no Axon beans were being wired, ever. That led me to investigate the process of creating fat JAR's step by step. First Maven, then Spring Boot with Maven, then Gradle with Spring Boot and finally with the Shadow plugin you are referring too.
This endeavour landed me on this issue, which states as much as "projects which require the use of META-INF files need to add this to the shadow plugin, and this should be documented".
The portion referenced through this is the following:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CommandBus
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page