Search code examples
spring-bootkotlinamazon-sqsjava-17

Spring boot 3 and JMS configuration for Amazon SQS


The latest spring boot (i.e. 3.0.1) uses Spring JMS 6.0.3. And the latest Spring JMS that comes with the latest spring boot for ConnectionFactory uses jakarta.jms.ConnectionFactory, while the older JMS was using javax.jms.ConnectionFactory. This was my bean setup and configuration before:

@Configuration
@EnableJms
class JmsConfiguration {

    @Autowired
    private lateinit var sqsClient: SqsClient

    @Bean
    fun sqsConnectionFactory(): SQSConnectionFactory =
        SQSConnectionFactory(ProviderConfiguration(), sqsClient)

    @Bean
    fun jmsListenerContainerFactory(): DefaultJmsListenerContainerFactory {
        val factory = DefaultJmsListenerContainerFactory()
        factory.setConnectionFactory(sqsConnectionFactory())
        factory.setDestinationResolver(DynamicDestinationResolver())
        factory.setSessionAcknowledgeMode(CLIENT_ACKNOWLEDGE)
        return factory
    }

    @Bean
    fun jmsTemplate(): JmsTemplate = JmsTemplate(sqsConnectionFactory())
}

However with the latest Spring boot, I cannot use SQSConnectionFactory, because it hasn't implemented its code based on jakarta rather javax.

Here are my SQS dependencies used:

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>sqs</artifactId>
            <version>2.19.19</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>amazon-sqs-java-messaging-lib</artifactId>
            <version>2.0.3</version>
        </dependency>

So now I cannot set the connection factory.setConnectionFactory(sqsConnectionFactory()), because it complains sqsConnectionFactory() is not type of jakarta ConnectionFactory. Is there any solution?


Solution

  • JMS has already published a dependency which supports Jakarta:

    <dependency>
        <groupId>jakarta.jms</groupId>
        <artifactId>jakarta.jms-api</artifactId>
    </dependency>