General Tech Bugs & Fixes . 1 year ago

Spring boot JMS Listener - org.springframework.jms.config.JmsListenerEndpointRegistry.isAutoStartup()Z Ask Question

Spring boot JMS Listener - org.springframework.jms.config.JmsListenerEndpointRegistry.isAutoStartup()Z Ask Question

2 views   1   0 likes   0 shares Tuteehub forum manpreet 1 answers
tuteehub_quiz
Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

profilepic.png

Tuteehub forum answer Answers (1)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 1 year ago

 

I have setup a JmsListener to read messages from a sqs queue. Firtsly i created a configuration class like below to setup a ConnectionFactory and JMSTemplate

 @Configuration
 @EnableJms
 public class SQSJmsConfig {
 private AWSCredentialsProvider awsCredentialsProvider;

 @Value("${aws.ses.accessKey}")
 private String accessKey;

 @Value("${aws.ses.secretKey}")
 private String secretKey;

 @Bean
 public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);

    SQSConnectionFactory sqsConnectionFactory = new SQSConnectionFactory(new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(awsCredentialsProvider));

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(sqsConnectionFactory);
    factory.setDestinationResolver(new DynamicDestinationResolver());
    factory.setConcurrency("3-10");
    factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    return factory;
}

@Bean
public JmsTemplate defaultJmsTemplate() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);

    SQSConnectionFactory sqsConnectionFactory = new SQSConnectionFactory(new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(awsCredentialsProvider));

    return new JmsTemplate(sqsConnectionFactory);
 }
}

Then i created a JmsListener method to read messages from sqs queue

@Service
public class SQSQueueService {
private static final Logger log = LoggerFactory.getLogger(SQSQueueService.class);

@JmsListener(destination = "${aws.sqs.queueName}")
public void readPlan(SQSEmailStatusQueue sqsEmailStatusQueue) {
    try {
        log.info("SNS notification received from SQS queue");
        String message = sqsEmailStatusQueue.getMessage();
        System.out.println(message);
    } catch (Exception e) 
													
													
2 views   0 shares
Related Tags

AskAnything Ask Anything

Ask Me Anything

ask me anything tuteehub

Hello! How can I assist you today?
Whether you have questions, need information, or just want to chat, feel free to let me know