Remote access to Command & EventBus via JMS/ActiveMQ (Spring Integration)

Hi,

Since a while I am looking into Axon in my spare time. Now I have the idea to develop a simple server backend based on Axon and a JavaFX based client. I have also spent time learning Spring Integration so I would like to integrate both system via JMS (ActiveMQ). It would look something like this:

±---------+ ±---------+

<------[JMS Queue (Commands)]-------> | Single |

Multiple | | Server |

Clients | | Instance |
(JavaFx) | | (Axon) |

<------[JMS Topic (Events)]---------> | |

±---------+ ±---------+

It this point I dont have to worry about scalability or performance or any other non-functional beceause this is a hobby project and enviroment. Therefore I didn’t see the need for multiple nodes having the domain and handling commands.

What would be the best (/not so complicated) way for me to do this?

At this point I see two options:

  1. Use the SimpleCommandBus & SimpleEventBus and write adapters for both. Then I would have to create an adapter for the commands which could be a simple @ServiceActivator method that receives an Command object and post it on the internal bus. The same could be done for the events by creating an eventhandler that posts the same event objects on a topic. The Commands and Events could be put in a seperate module so that they can both be used by Spring Integration as Axon. This is the option I am currently considdering the most beceause it is the most clear to me. I don’t know if there are any real downsides to this approach.

  2. I saw a post about creating a custom EventBusTerminal. I have no idea what work has to be done for this approach and i have no experience with setting up anything other then the SimpleCommand- & SimpleEventBus.

Any advice or other option that i did not mention?

Regards,

Joost van Weenen

Hi Joost,

putting commands and events in a separate module is a practice that I use myself as well. I call this the “core API”, as it is the true API to your application.

Creating adapters is probably the easiest approach. If you’re using Spring Messaging (the API that Spring integration also uses), you can find some adapters in the axon-springmessaging module. If you’re required to use Spring 3.x, you can use the axon-integration module, which uses the Spring integration API directly.

The EventBusTerminal is useful if you want to route event through a message broker (both sending and receiving). If you just want to offload events to a mesage bus, but use the “normal” event bus mechanism for the rest of the application, it’s easier to just configure an Event Handler that sends events to the broker.

Hope this helps.
Cheers,

Allard

Hi,

I have checked out axon-integration. One last check if I have understood correctly:

Events publishing on JMS
So I should be able to use the EventListeningMessageChannelAdapter to publish events to a MessageChannel and then i can connect that channel to an JmsOutboundGateway to publish the events on a topic for any other client?

Command receiving from JMS
At this point I had already created a Service class that could handle messages incomming in from JMS. I configured Spring integration like this: jms-inbound-gateway => my-commands-channel => my-command-handling-service

Then the service activator could look as simple as this? The support for multiple commands comes from polymorpishm so i dont need a lot of ServiceActivators:

@Component
public class SomeService {
@Autowired
private CommandGateway commandGateway;

@ServiceActivator
public Boolean handleIncommingCommand(SomeCommand command) {
commandGateway.send(command);
return true;
}

}

Regards,

Joost van Weenen

It’s as simple as that. Do note that the CommandGateway method you’re invoking is a fire and forget one. If the command fails, it still consumes the message from the queue.

Cheers,

Allard

Joost,
Your are publishing an Event to the JMS queue, then why are you listening for a command on the other side of queue?
I am also trying to publish events to a JMS queue and subscribe to events on a remote machine, but I did not understand your approach.

Hi skconnect2000,

I was talking about two separate applications. The clients would send commands (immutable) via JMS to a server. The server would receive the commands and post them to the internal axon bus for further handling. This would result in an event that could be sent back to the client, again via JMS.
The alternative setup would probably to use some sort of shared bus of the axon framework between the client/server but that was a bit too complicated for me :slight_smile:

I guess the corrected picture looks more like this (note the arrows):

±---------+ ±---------+

------[JMS Queue (Commands)]-------> | Single |

Multiple | | Server |

Clients | | Instance |
(JavaFx) | | (Axon) |

<------[JMS Topic (Events)]--------- | |

±---------+ ±---------+

The advantage would be that the client wouldn’t know anything else of DDD except for the fact that it sends commands and receives events. But those objects act as immutable DTOs anyway so they are perfect for the separation of the server and client program.

Regards,

Joost van Weenen

Joost,
Thanks for your reply.
How is the client listening to a published event? Are you wiring everything at the client side with Axon event listener or your reading JMS message and then identifying the type of event.
Is your code available on Github?

Thanks,
SK