【问题标题】:Not able to configure durable subscriber in JMS with Spring Boot无法使用 Spring Boot 在 JMS 中配置持久订阅者
【发布时间】:2020-10-30 07:02:49
【问题描述】:

我正在使用 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.

下面是使用 Spring Boot 的完整 ActiveMQ 设置。

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.

我的应用程序有独立的生产者和消费者。我确实尝试用谷歌搜索错误,但没有任何帮助。

【问题讨论】:

    标签: spring-boot jms-topic


    【解决方案1】:

    迟到的答案。这对我有用。

    1. 使用 SingleConnectionFactory 代替 ConnectionFactory
    2. 将客户端 ID 设置为 SingleConnectionFactory
    3. 不要将客户端 ID 设置为工厂
        public JmsListenerContainerFactory<?> connectionFactory(SingleConnectionFactory connectionFactory,
                    DefaultJmsListenerContainerFactoryConfigurer configurer) {
            // Add this
            connectionFactory.setClientId("your-client-id")
            // Do not do this
            //factory.setClientId("brokerClientId"); 
    

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      • 2013-12-17
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多