Error Persisting Object Created from event sent over rabbit

Hi all,

I have two services with one of them listening to a certain event from the other through rabbit to update it’s own model. Each time I send the event, I get an exception in the receiving service and it keeps repeating itself as the service retries to consume the message.

`
org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener method ‘public void org.softech.organisation.configuration.OrganisationConfig$1.onMessage(org.springframework.amqp.core.Message,com.rabbitmq.client.Channel) throws java.lang.Exception’ threw exception at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:140) ~[spring-rabbit-1.7.3.RELEASE.jar:na]

Caused by: org.axonframework.eventsourcing.eventstore.EventStoreException: An event for aggregate [9170c250-ed4f-45d5-a2a0-fd695bf46304] at sequence [4] could not be persisted at org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine.handlePersistenceException(AbstractEventStorageEngine.java:112) ~[axon-core-3.0.4.jar.0.4]

Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process ‘persist’ call at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:282) ~[spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE] at com.sun.proxy.$Proxy114.persist(Unknown Source) ~[na:na]

`

Anybody with an idea?

Found the problem. I had to annotate the the spingmessagesource with @Transactional. Though I now noticed I have to implement a saga so that a failure is bubbled up to other service

`

@Bean
public SpringAMQPMessageSource cmsEvents(Serializer serializer) {
    return new SpringAMQPMessageSource(new DefaultAMQPMessageConverter(serializer)){

        @Transactional
        @RabbitListener(queues = "UserQueue")
        @Override
        public void onMessage(Message message, Channel channel) throws Exception {
            super.onMessage(message, channel);
        }
    };
}

`