问题描述
我在项目中使用Apache Camel,并将其嵌入到Spring Boot应用程序中。我的要求是从Apache Active MQ Artemis(嵌入在JBoss EAP 7.2.0中)读取消息到IBM MQ。这两个队列都在我当前服务器的远程位置。 Spring Boot项目将作为war文件部署到JBoss EAP 7.2.0服务器。
我已经开发了一个独立程序,该程序可以从Apache Active MQ Artemis中读取消息并将消息写入其中。我已经在Spring Boot配置类中创建了连接工厂。下面是我的Spring Boot配置类和路由类:
@SpringBootApplication
@EnableJms
public class SpringMqDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringMqDemoApplication.class,args);
}
private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory";
private static final String CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
@Bean
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");
}
return null;
}
public Properties getEnvProperties() {
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL,"http-remoting://<<IP>>:8080");
env.put(Context.Security_PRINCIPAL,"username");
env.put(Context.Security_CREDENTIALS,"password");
return env;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
JndiDestinationResolver jndiDestinationResolver = new JndiDestinationResolver();
jndiDestinationResolver.setJndiEnvironment(getEnvProperties());
factory.setDestinationResolver(jndiDestinationResolver);
return factory;
}
@Component
public class Route extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:producer")
.log("Camel route")
.to("jms:queue:queue1");
from("jms:queue:queue2")
.log("Camel route: ${body}")
.to("someEndpoint");
}
}
使用此示例程序,我能够写入队列1并从队列2读取数据,但是在这里,我对两个队列使用相同的ConnectionFactory。在我的项目中,我将必须使用两个连接工厂,有人可以指导我如何对两个队列使用两个连接工厂吗?
我浏览了JMS端点的文档,但是不确定在骆驼jms端点上为参数“ connectionFactory”使用什么值。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)