Search code examples
javamongodbquarkusquarkus-panachequarkus-reactive

Pubsub message with reactive panache monogodb failing to create ReactiveTransaction with session is null error


I have a quarkus project connecting to monogdb using reactive panache.

I would like my method to be wrapped in a transaction and my current code looks roughly as follows:

@Traced
@ApplicationScoped
@Startup
public class MyReceiver implements com.google.cloud.pubsub.v1.MessageRecevier {
    @Override
    @ActivateRequestContext
    public void receiveMessage(PubsubMessage pubsubMessage, AckReplyConsumer ackReplyConsumer) {
        try {
            final String messageStr = pubsubMessage.getData().toStringUtf8();
            final MyMessage messageContent = objectMapper.readValue(messageStr, getTypeReference());
            handleMessage(messageContent).await().indefinitely();

            ackReplyConsumer.ack();
        } catch (Throwable ex) {
            log.warn("{} Message ID: [{}]  on [{}] ", ex.getMessage(), pubsubMessage.getMessageId(), subscriptionName);
            ackReplyConsumer.nack();
        }
    }

    public TypeReference<MyMessage> getTypeReference() { 
      return new TypeReference<>(){};
    }

    @ReactiveTransactional
    public Uni<Void> handleMessage(MyMessage message) {
        // code here is never reached
    }

}

When i try to test my code however and get a message,

I am getting this error: java.lang.NullPointerException: Cannot invoke "org.hibernate.reactive.mutiny.Mutiny$Session.withTransaction(java.util.function.Function)" because "session" is null

And it happens when the code tries to go into handleMessage, so when the aspect for @ReactiveTransactional is being triggered

What can I look out for that is causing this cause I can't find anything that can be the source of the issue.


Solution

  • It seems at the moment, panache does not support transactions in mongodb which was the source of this issue.