Подключение к удаленной очереди jms с помощью Spring Boot - PullRequest
0 голосов
/ 27 мая 2020

Я пытаюсь подключить удаленную очередь JBOSS, JBOSS EAP 7, JMS с весенней загрузкой. Под моим кодом у меня есть только класс конфигурации и класс потребителя. Я просматриваю журналы, которые подключаюсь к localhost, но ... ПОЧЕМУ ???

@Configuration
@EnableJms
public class ActiveMqConnectionFactoryConfig {

    String queueName= "JMSTestQueueName";
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
    private static final String CONNECTION_FACTORY = "jms/RemoteConnectionFactory";

    public ConnectionFactory connectionFactory() {

        try {

            System.out.println("Retrieving JMS queue with JNDI name: " + CONNECTION_FACTORY);
            JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
            jndiObjectFactoryBean.setJndiName(CONNECTION_FACTORY);
            jndiObjectFactoryBean.setJndiEnvironment(getEnvProperties());       
            jndiObjectFactoryBean.afterPropertiesSet();

            return (QueueConnectionFactory) jndiObjectFactoryBean.getObject();

        } catch (NamingException e) {
            System.out.println("Error while retrieving JMS queue with JNDI name: [" + CONNECTION_FACTORY + "]");
        } catch (Exception ex) {
            System.out.println("Error error");
            ex.getStackTrace();
        }
        return null;
    }


    @Bean
    Properties getEnvProperties() throws NamingException {
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
        env.put(Context.PROVIDER_URL, "http-remoting://<REMOTE_ADDRESS>:8080?broker.persistent=false&broker.useJmx=false");
        env.put(Context.SECURITY_PRINCIPAL, <USER>);
        env.put(Context.SECURITY_CREDENTIALS, <PASSWORD>);
        namingContext = new InitialContext(env);
        return env;
    }

    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) throws NamingException {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setConcurrency("3-10");
        JndiDestinationResolver jndiDestinationResolver = new JndiDestinationResolver();
        jndiDestinationResolver.setJndiEnvironment(getEnvProperties());
        factory.setDestinationResolver(jndiDestinationResolver);
        return factory;

    }
}

Класс слушателя:

@Configuration
public class jmsListener {

    @JmsListener(destination = "queue/JMSTestQueueName", containerFactory = "jmsListenerContainerFactory")
    public void receive(Message message) {
        System.out.println("Received Message: " + message);
    }   
}

Журнал:

2020-05-27 00:21:58.571  INFO 10368 --- [           main] o.apache.activemq.broker.BrokerService   : Apache ActiveMQ 5.15.7 (localhost, ID:ITPC020248-60530-1590531718443-0:1) is starting
2020-05-27 00:21:58.576  INFO 10368 --- [           main] o.apache.activemq.broker.BrokerService   : Apache ActiveMQ 5.15.7 (localhost, ID:ITPC020248-60530-1590531718443-0:1) started 
2020-05-27 00:21:58.577  INFO 10368 --- [           main] o.apache.activemq.broker.BrokerService   : For help or more information please see: http://activemq.apache.org 
2020-05-27 00:21:58.617  INFO 10368 --- [           main] o.a.activemq.broker.TransportConnector   : Connector vm://localhost started 
2020-05-27 00:21:58.659  INFO 10368 --- [           main] jboss.ConsumerClass                      : Started ConsumerClass in 1.922 seconds (JVM running for 3.504)

Без ?broker.persistent=false&broker.useJmx=false в URL-адресе JNDI я получаю следующее:

2020-05-27 19:38:34.680  INFO 19752 --- [dpoint" task-13] org.jboss.ejb.client.remoting            : EJBCLIENT000016: Channel Channel ID 8f759d73 (outbound) of Remoting connection 336369ee to /172.16.68.80:8080 can no longer process messages
2020-05-27 19:38:37.479  INFO 19752 --- [           main] jboss.ConsumerClass                      : Started ConsumerClass in 7.194 seconds (JVM running for 9.26)
2020-05-27 19:38:42.772 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:38:48.068 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:38:53.401 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=2, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:38:58.699 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=3, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:39:04.006 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=4, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:39:09.320 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=5, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user

1 Ответ

0 голосов
/ 27 мая 2020

Ваш connectionFactory() должен быть @Bean, чтобы ввести его в качестве аргумента в метод фабрики контейнера.

public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) throws NamingException {

Поскольку это не @Bean, вы получаете загрузку по умолчанию фабрика соединений (предположительно, у вас есть ActiveMQ на пути к классам).

...