简体   繁体   English

ActiveMQ Artemis 和 5.x 同时侦听器 - NullPointerException

[英]ActiveMQ Artemis and 5.x listeners at same time - NullPointerException

I have a legacy Spring 4.2.1.RELEASE application that connects to ActiveMQ 5.x as a listener and now we're adding connectivity to ActiveMQ Artemis.我有一个旧的 Spring 4.2.1.RELEASE 应用程序,它作为侦听器连接到 ActiveMQ 5.x,现在我们正在添加到 ActiveMQ Artemis 的连接。 For Artemis we're using durable subscriptions because we don't want message loss on a topic when the subscribers go down and shared subscriptions because we wanted the option of clustering or using concurrency to asynchronously process the messages in the subscription.对于 Artemis,我们使用持久订阅是因为我们不希望订阅者宕机时主题上的消息丢失,而共享订阅是因为我们希望选择集群或使用并发来异步处理订阅中的消息。 I have separate ConnectionFactory s and ListenerContainer s, but from this WARN log that keeps repeating it looks like the Artemis DMLC can't start due to the following NPE:我有单独的ConnectionFactoryListenerContainer ,但是从这个不断重复的WARN日志看来,由于以下 NPE,Artemis DMLC 无法启动:

java.lang.NullPointerException
    at org.springframework.jms.listener.AbstractMessageListenerContainer.createConsumer(AbstractMessageListenerContainer.java:856)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:213)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1173)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1149)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1142)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1039)
    at java.lang.Thread.run(Unknown Source)

On the surface it looks like it can't find the method createSharedDurableConsumer .从表面上看,它似乎找不到createSharedDurableConsumer方法。 Looking at the AbstractMessageListenerContainer I have, line 856 is calling method.invoke查看我拥有的AbstractMessageListenerContainer ,第 856 行正在调用 method.invoke

/** The JMS 2.0 Session.createSharedDurableConsumer method, if available */
private static final Method createSharedDurableConsumerMethod = ClassUtils.getMethodIfAvailable(
        Session.class, "createSharedDurableConsumer", Topic.class, String.class, String.class);

...

Method method = (isSubscriptionDurable() ?
                        createSharedDurableConsumerMethod : createSharedConsumerMethod);
try {
    return (MessageConsumer) method.invoke(session, destination, getSubscriptionName(), getMessageSelector());
}

Artemis configuration:阿尔忒弥斯配置:

@Configuration
public class ArtemisConfig {

    @Autowired
    private Environment env;

    @Bean
    public ConnectionFactory artemisConnectionFactory() {
        ActiveMQConnectionFactory artemisConnectionFactory = ActiveMQJMSClient
                .createConnectionFactoryWithHA(JMSFactoryType.CF, createTransportConfigurations());

        artemisConnectionFactory.setUser(env.getRequiredProperty("artemis.username"));
        artemisConnectionFactory.setPassword(env.getRequiredProperty("artemis.password"));
        artemisConnectionFactory.setCallTimeout(env.getRequiredProperty("artemis.call.timeout.millis", Long.class));
        artemisConnectionFactory.setConnectionTTL(env.getRequiredProperty("artemis.connection.ttl.millis", Long.class));
        artemisConnectionFactory
                .setCallFailoverTimeout(env.getRequiredProperty("artemis.call.failover.timeout.millis", Long.class));
        artemisConnectionFactory.setInitialConnectAttempts(
                env.getRequiredProperty("artemis.connection.attempts.initial", Integer.class));
        artemisConnectionFactory
                .setReconnectAttempts(env.getRequiredProperty("artemis.connection.attempts.reconnect", Integer.class));
        artemisConnectionFactory.setRetryInterval(env.getRequiredProperty("artemis.retry.interval.millis", Long.class));
        artemisConnectionFactory
                .setRetryIntervalMultiplier(env.getRequiredProperty("artemis.retry.interval.multiplier", Double.class));
        artemisConnectionFactory.setBlockOnAcknowledge(true);
        artemisConnectionFactory.setBlockOnDurableSend(true);
        artemisConnectionFactory.setCacheDestinations(true);
        artemisConnectionFactory.setConsumerWindowSize(0);
        artemisConnectionFactory.setMinLargeMessageSize(1024 * 1024);

        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(artemisConnectionFactory);

        cachingConnectionFactory
        .setSessionCacheSize(env.getRequiredProperty("artemis.session.cache.size", Integer.class));
        cachingConnectionFactory.setReconnectOnException(true);

        return cachingConnectionFactory;
    }

    @Bean
    public DefaultJmsListenerContainerFactory artemisContainerFactory(ConnectionFactory artemisConnectionFactory,
            JmsTransactionManager artemisJmsTransactionManager,
            MappingJackson2MessageConverter mappingJackson2MessageConverter) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

        factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
        factory.setConnectionFactory(artemisConnectionFactory);
        factory.setDestinationResolver(new DynamicDestinationResolver());
        factory.setMessageConverter(mappingJackson2MessageConverter);
        factory.setSubscriptionDurable(Boolean.TRUE);
        factory.setSubscriptionShared(Boolean.TRUE);
        factory.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED);
        factory.setSessionTransacted(Boolean.TRUE);
        factory.setTransactionManager(artemisJmsTransactionManager);

        return factory;
    }

    private TransportConfiguration[] createTransportConfigurations() {
        String connectorFactoryFqcn = NettyConnectorFactory.class.getName();
        Map<String, Object> primaryTransportParameters = new HashMap<>(2, 1F);
        String primaryHostname = env.getRequiredProperty("artemis.primary.hostname");
        Integer primaryPort = env.getRequiredProperty("artemis.primary.port", Integer.class);

        primaryTransportParameters.put("host", primaryHostname);
        primaryTransportParameters.put("port", primaryPort);

        return new TransportConfiguration[] {
                new TransportConfiguration(connectorFactoryFqcn, primaryTransportParameters),
                new TransportConfiguration(connectorFactoryFqcn, backupTransportParameters) };
    }
}

My pom uses version 2.10.0 of Artemis.我的 pom 使用 Artemis 2.10.0 版。

How do I fix this?我该如何解决?

The JMS 2.0 spec is backwards compatible with JMS 1.1 so make sure you only have the JMS 2 spec on your classpath. JMS 2.0 规范向后兼容 JMS 1.1,因此请确保您的类路径中只有 JMS 2 规范。 My hunch is that the reflection calls in the Spring code are getting messed up because they're hitting the JMS 1.1 spec classes instead of the proper JMS 2 spec classes.我的预感是 Spring 代码中的反射调用变得一团糟,因为它们命中 JMS 1.1 规范类而不是正确的 JMS 2 规范类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 虚拟主题在使用 ActiveMQ 5.x 的连接工厂时有效,但不是 Artemis 的连接工厂 - Virtual topics work when using ActiveMQ 5.x's connection factory, but not Artemis' connection factory ActiveMQ 5.x 和 DurableConsumer - ActiveMQ 5.x and DurableConsumer 如果所有侦听器都被销毁,为什么 ActiveMQ Artemis 会自动删除地址? - Why ActiveMQ Artemis auto delete address if all listeners are destroyed? 如何添加第二个资源适配器以同时使用ibm mq(WebSphere)和ActiveMQ(Artemis)? - How can i add second resource adapter to work with ibm mq (WebSphere) and ActiveMQ (Artemis) at the same time? 如何使用 ActiveMQ 5.x 检索 session 的创建主题(和队列) - How to retrieve created Topics (and Queues) of session with ActiveMQ 5.x 带有独立 ActiveMQ 的 Wildfly 上的 ActiveMQ Artemis - ActiveMQ Artemis on wildfly with standalone ActiveMQ Apache ActiveMQ Artemis客户端可以连接到现有的ActiveMQ代理5.15.X吗? - Can an Apache ActiveMQ Artemis client connect to an existing ActiveMQ broker 5.15.X? Apache ActiveMQ Artemis速度下降 - Apache ActiveMQ Artemis slowdown 在 ActiveMQ Artemis 上配置 TLS - Configure TLS on ActiveMQ Artemis 在单独的线程或同一线程中创建ActiveMQ侦听器的区别 - Difference in creating ActiveMQ listeners in separate threads or in a same thread
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM