Hi all,
I’ve got this command handler that sends events over rabbit
@CommandHandler
public Profession(AddProfessionCommand command) {
JSONObject jsonEvent = new JSONObject();
jsonEvent.put("event", "ProfessionAddedEvent");
jsonEvent.put("professionId", command.getProfessionId().toString());
jsonEvent.put("profession", command.getProfession());
jsonEvent.put("userId", command.getUserId().toString());
apply(new ProfessionAddedEvent(command.getProfessionId(), command.getProfession(), command.getUserId())).
andThenApply(()-> jsonEvent);
}
which I handle in two different services as such
@EventHandler
public void on(JSONObject event) {
System.out.println(event);
switch (event.getString("event")){
case "ProfessionAddedEvent":
FutureCallback<AddProfessionCommand, String> callback = new FutureCallback<>();
commandGateway.send(new AddProfessionCommand(new ProfessionId(event.getString("professionId")),
event.getString("profession"), new UserId(event.getString("userId"))));
The problem is that in one of the services, I have multiple queues listening to events of type org.Json.JSONObject.
@Bean
public SpringAMQPMessageSource cmsEvents(Serializer serializer)
{
return new SpringAMQPMessageSource(new DefaultAMQPMessageConverter(serializer)){
@Transactional
@RabbitListener(queues = {"CityQueue", "ProfessionQueue", "AddressQueue", "IncomeQueue"})
@Override
public void onMessage(Message message, Channel channel) throws Exception {
super.onMessage(message, channel);
}
};
}
So when the event comes, it is handled by the handler for one of the queues, then for every other queue which received a JSONObject event. And for some reason the command above (AddProfessionCommand) sends and event with exactly the same Id which generates the error below that keeps running infinitely:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry ‘33e7d070-e433-47f9-97c1-f986ea075f78-0’ for key 'UK8s1f994p4la2ipb13me2xqm
My question is: Is there a way to send an event to a specific queue over rabbit or make a handler handle events only from a spoecific queue? Thanks