【问题标题】:Getting an error "Cause: AMQ119031: Unable to validate user" in Spring-Boot app在 Spring-Boot 应用程序中收到错误“原因:AMQ119031:无法验证用户”
【发布时间】:2018-04-03 19:16:24
【问题描述】:

我在尝试连接部署在 JBoss EAP 7.1 上的 ActiveMQ Artemis 队列时遇到以下错误。

错误:DefaultMessageListenerContainer:无法刷新 JMS 目标“jms/queue/QueueA”的连接 - 重试使用 FixedBackOff{interval=5000, currentAttempts=139, 最大尝试=无限}。原因:AMQ119031:无法验证用户

这是我正在使用的代码:

@Bean public DefaultMessageListenerContainer myFactory() throws NamingException { 
   DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
   listenerContainer.setConnectionFactory(getConnectionFactory());
   listenerContainer.setDestinationName("jms/queue/QueueA");
   listenerContainer.setMessageListener(new MessageReceiver());
   return listenerContainer; 
}

private ConnectionFactory getConnectionFactory() throws NamingException { 
   final Properties env = new Properties();
   env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory); 
   env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); 
   env.put(Context.SECURITY_PRINCIPAL, "Username"); 
   env.put(Context.SECURITY_CREDENTIALS, "Password"); 
   InitialContext ic = new InitialContext(env); 
   return (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory");
}

【问题讨论】:

  • 您能否提供使用 DefaultMessageListenerContainer 的代码和/或配置?
  • @Bean public DefaultMessageListenerContainer myFactory() 抛出 NamingException { DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer(); listenerContainer.setConnectionFactory(getConnectionFactory()); listenerContainer.setDestinationName("jms/queue/QueueA"); listenerContainer.setMessageListener(new MessageReceiver());返回侦听器容器; }
  • 私有 ConnectionFactory getConnectionFactory() 抛出 NamingException { final Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory); env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080"); env.put(Context.SECURITY_PRINCIPAL, "用户名"); env.put(Context.SECURITY_CREDENTIALS, "密码"); InitialContext ic = new InitialContext(env); return (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory"); }

标签: spring-boot microservices spring-jms jboss-eap-7 activemq-artemis


【解决方案1】:

如错误消息(即AMQ119031: Unable to validate user)所示,您在创建 JMS 连接时没有提供正确的凭据。

您在属性中为 JNDI 查找提供的用户名和密码信息适用于 JNDI 查找(即适用于 JMS 连接)。 JNDI 和 JMS 100% 相互独立。

您必须使用您的 JMS 用户名和密码配置适当的 Spring 组件,以便在调用 javax.jms.ConnectionFactory.createConnection(String,String)javax.jms.ConnectionFactory.createContext(String,String) 时可以使用它。尝试从您的 getConnectionFactory() 方法返回 UserCredentialsConnectionFactoryAdapter 的实例。

【讨论】:

  • 你能帮我弄清楚如何以及哪个 Spring 组件必须配置用户名和密码。我还没有看过任何在 Spring 中这样做的文章(创建连接,上下文)
  • 谢谢贾斯汀。我成功地连接并读取了来自 Queue 的消息。下面是我修改后的 getConnectionFactory()
  • 帖子中getConnectionFactory代码的补充:ConnectionFactory connectionFactory = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory"); UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter(); userCredentialsConnectionFactoryAdapter.setUsername("用户名"); userCredentialsConnectionFactoryAdapter.setPassword("密码"); userCredentialsConnectionFactoryAdapter.setTargetConnectionFactory(connectionFactory);返回 userCredentialsConnectionFactoryAdapter;
猜你喜欢
  • 2016-07-25
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 2020-05-10
  • 2016-12-23
  • 2019-02-07
  • 2020-01-28
相关资源
最近更新 更多