Невозможно настроить постоянного подписчика в JMS с помощью Spring Boot - PullRequest
0 голосов
/ 09 июля 2020

Я использую Apache ActiveMQ 5.15.13 и Spring Boot 2.3.1.RELEASE. Я пытаюсь настроить постоянного абонента, но не могу. Мое приложение во время выполнения выдает ошибку:

Cause: setClientID call not supported on proxy for shared Connection. Set the 'clientId' property on the SingleConnectionFactory instead.

Ниже приведена полная настройка ActiveMQ с Spring Boot.

JMSConfiguration

public class JMSConfiguration
{
    @Bean
    public JmsListenerContainerFactory<?> connectionFactory(ConnectionFactory connectionFactory,
            DefaultJmsListenerContainerFactoryConfigurer configurer)
    {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        // This provides all boot's default to this factory, including the message converter
        configurer.configure(factory, connectionFactory);
        // You could still override some of Boot's default if necessary.
        factory.setPubSubDomain(true);
        
        /* below config to set durable subscriber */
         factory.setClientId("brokerClientId"); 
         factory.setSubscriptionDurable(true);
            
       // factory.setSubscriptionShared(true);
        return factory;
    }

    @Bean
    public MessageConverter jacksonJmsMessageConverter()
    {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setTargetType(MessageType.TEXT);
        converter.setTypeIdPropertyName("_type");
        return converter;
    }
}

Класс приемника

public class Receiver {

private static final String MESSAGE_TOPIC = "message_topic";
private Logger logger = LoggerFactory.getLogger(Receiver.class);

private static AtomicInteger id = new AtomicInteger();

@Autowired
ConfirmationReceiver confirmationReceiver;
    
    @JmsListener(destination = MESSAGE_TOPIC,
            id = "comercial",
            subscription = MESSAGE_TOPIC,
            containerFactory = "connectionFactory")
    public void receiveMessage(Product product, Message message)
    {
        logger.info(" >> Original received message: " + message);
        logger.info(" >> Received product: " + product);
        
        System.out.println("Received " + product);
        
        confirmationReceiver.sendConfirmation(new Confirmation(id.incrementAndGet(), "User " +
                    product.getName() + " received."));
    }
}

application.properties

spring.jms.pub-sub-domain=true
spring.jms.listener.concurrency=1
spring.jms.listener.max-concurrency=2
spring.jms.listener.acknowledge-mode=auto
spring.jms.listener.auto-startup=true
spring.jms.template.delivery-mode:persistent
spring.jms.template.priority: 100
spring.jms.template.qos-enabled: true
spring.jms.template.receive-timeout: 1000
spring.jms.template.time-to-live: 36000

Когда я пытаюсь запустить приложение, оно выдает ошибку, как показано ниже

Could not refresh JMS Connection for destination 'message_topic' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: setClientID call not supported on proxy for shared Connection. Set the 'clientId' property on the SingleConnectionFactory instead.

У моего приложения есть автономный производитель и потребитель. Я попытался найти ошибку в Google, но ничего не помогло.

...