Как настроить несколько JmsListener для нескольких AWS SQS - PullRequest
0 голосов
/ 06 ноября 2019
@EnableJms
@Configuration
public class SqsConfig {

    @Bean
    public SQSConnectionFactory sqsConnectionFactory(SqsProperties sqsProperties) {
        AmazonSQS sqs = AmazonSQSClientBuilder.standard().withRegion(
                String.valueOf(RegionUtils.getRegion(sqsProperties.getRegion()))).build();
        return new SQSConnectionFactory(new ProviderConfiguration(), sqs);
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
            SQSConnectionFactory connectionFactory, MessageConverter messageConverter, ErrorHandler errorHandler, SqsProperties sqsProperties) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setDestinationResolver(new DynamicDestinationResolver());
        factory.setConcurrency(sqsProperties.getConcurrency());
//        factory.setMessageConverter(messageConverter);
        factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
        factory.setErrorHandler(errorHandler);
        return factory;
    }

    @Bean
    public MessageConverter messageConverter(ObjectMapper objectMapper) {
        MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
        mappingJackson2MessageConverter.setObjectMapper(objectMapper);
        mappingJackson2MessageConverter.setTargetType(MessageType.TEXT);
        mappingJackson2MessageConverter.setTypeIdPropertyName("_type");
        return mappingJackson2MessageConverter;
    }

}
@Component
@RequiredArgsConstructor
public class SqsMessageListener {

    private final SubscriptionMapper subscriptionMapper;
    private final SubscriptionService subscriptionService;
    private final SnsProducer snsProducer;



    @JmsListener(destination = "${aws.sqs.createSubscription}")
    public void createSubscription(String receivedMsg) {


            System.out.println(receivedMsg);


    }

    @JmsListener(destination = "${aws.sqs.cancelSubscription}")
    public void cancelSubscription(String receivedMsg)  {

            System.out.println(receivedMsg);


    }

}

В моем проекте я добавляю два разных JmsListener с SQS AWS

Поэтому я должен добавить отдельную конфигурацию jmsListenerContainerFactory для каждого JmsListener ??

AmazonClientException: receiveMessage Невозможно выполнитьHTTP-запрос: время ожидания подключения из пула

...