micronaut-projects / micronaut-jms

Integration between Micronaut and JMS
Apache License 2.0
15 stars 14 forks source link

Support AWS SQS FIFO queues #221

Open johndevs opened 2 years ago

johndevs commented 2 years ago

Expected Behavior

I expect the examples in the documentation to work with Amazon SQS Fifo queues

Actual Behaviour

When sending a message the following exception is thrown:

18:17:25.996 ERROR c.a.s.j.AmazonSQSMessagingClientWrapper - AmazonServiceException: sendMessage. RequestId: 78676d41-b0bc-50f9-ab6b-37d404d947a7
HTTPStatusCode: 400 AmazonErrorCode: MissingParameter
com.amazonaws.services.sqs.model.AmazonSQSException: The request must contain the parameter MessageGroupId. (Service: AmazonSQS; Status Code: 400; Error Code: MissingParameter; Request ID: 78676d41-b0bc-50f9-ab6b-37d404d947a7; Proxy: null)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1862)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1415)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1384)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1154)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:811)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:779)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:753)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:713)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:695)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:559)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:539)
    at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2271)
    at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2238)
    at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2227)
    at com.amazonaws.services.sqs.AmazonSQSClient.executeSendMessage(AmazonSQSClient.java:1817)
    at com.amazonaws.services.sqs.AmazonSQSClient.sendMessage(AmazonSQSClient.java:1786)
    at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.sendMessage(AmazonSQSMessagingClientWrapper.java:202)
    at com.amazon.sqs.javamessaging.SQSMessageProducer.sendInternal(SQSMessageProducer.java:143)
    at com.amazon.sqs.javamessaging.SQSMessageProducer.send(SQSMessageProducer.java:359)
    at com.amazon.sqs.javamessaging.SQSMessageProducer.send(SQSMessageProducer.java:384)
    at io.micronaut.jms.templates.JmsProducer.send(JmsProducer.java:162)
    at io.micronaut.jms.templates.JmsProducer.send(JmsProducer.java:90)
    at io.micronaut.jms.configuration.JMSProducerMethodInterceptor.intercept(JMSProducerMethodInterceptor.java:116)
    at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
    at com.devsoap.hits.aws.AmazonSqsService$MessageProducer$Intercepted.send(Unknown Source)
    at com.devsoap.hits.aws.AmazonSqsService.onApplicationEvent(AmazonSqsService.java:33)
    at com.devsoap.hits.aws.AmazonSqsService.onApplicationEvent(AmazonSqsService.java:18)
    at io.micronaut.context.event.ApplicationEventPublisherFactory.notifyEventListeners(ApplicationEventPublisherFactory.java:262)
    at io.micronaut.context.event.ApplicationEventPublisherFactory.access$200(ApplicationEventPublisherFactory.java:60)
    at io.micronaut.context.event.ApplicationEventPublisherFactory$2.publishEvent(ApplicationEventPublisherFactory.java:229)

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

3.1.1

marcmarcet commented 2 years ago

I think you can use fifo queues by just setting the right message headers. Something like this should work:

@JMSProducer(CONNECTION_FACTORY_BEAN_NAME)
interface TestProducer {
    @Queue("my-queue-name.fifo")
    fun send(
        @MessageBody message: String,
        @MessageHeader("JMSXGroupID") messageGroupId: String,
        @MessageHeader("JMS_SQS_DeduplicationId") messageDeduplicationId: String
    )
}
elliottpope commented 2 years ago

@johndevs can you confirm whether the provided solution works for your use case?

Kumar2106 commented 1 year ago

@elliottpope I am also facing the same issue, I have tried the solution given by @marcmarcet but it is not working.