用于在VM外部发送消息的连接工厂是什么?
我在 JBOSS / standalone / configuration / configuration_full.xml 两个工厂中看到: InVmConnectionFactory 和 RemoteConnectionFactory 。
这是唯一可用的工厂吗?
我的实际配置是:
SERVER standalone_full.xml
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<hornetq-server>
...
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="RemoteConnectionFactory"/>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
</subsystem xmlns="urn:jboss:domain:messaging:1.1">
</hornetq-server>
</subsystem xmlns="urn:jboss:domain:messaging:1.1">
REMOTE MASCINE standalone_full.xml
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<hornetq-server>
...
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<jms-connection-factories> same factories as SERVER </jms-connection-factories>
<jms-destinations>
<jms-queue name="remoteQueue">
<entry name="jms/remoteQueue"/>
<entry name="java:jboss/exported/jms/queue/remoteQueue"/>
</jms-queue>
</jms-destinations>
</subsystem xmlns="urn:jboss:domain:messaging:1.1">
</hornetq-server>
</subsystem xmlns="urn:jboss:domain:messaging:1.1">
从SERVER端查找, server-application.ear :
ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/RemoteConnectionFactory");
Destination destination = (Destination) ctx.lookup("jms/queue/remoteQueue");
上下文构建如:
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put(Context.PROVIDER_URL, "remote://" + messageConnection.getHost() + ":" + messageConnection.getPort());
properties.put(Context.SECURITY_PRINCIPAL, messageConnection.getUsername());
properties.put(Context.SECURITY_CREDENTIALS, messageConnection.getPassword());
Context ctx = new InitialContext(properties);
我得到错误:
Caused by: java.io.NotSerializableException: org.hornetq.api.core.client.loadbalance.RoundRobinConnectionLoadBalancingPolicy
Caused by: an exception which occurred:
in field loadBalancingPolicy
in field serverLocator
in object org.hornetq.jms.client.HornetQJMSConnectionFactory@36cdb608
如果我尝试在同一个jboss(相同的VM)中部署应用程序 server-application.ear 和 remote-application.ear ,则消息处理正常。
当我使用两个jbosses(在同一台机器中)时会出现此问题。
任何人都有任何想法?
提前谢谢。
答案 0 :(得分:0)
InVmConnectionFactory引用in-vm-connector,当客户端和服务器在同一JVM中运行时,可用于发送和接收消息。 RemoteConnectionFactory引用netty连接器,可用于在客户端和服务器在不同JVM中运行时发送和接收消息。您可以基于连接器定义自己的连接工厂。
关于错误,您可以发布完整的堆栈跟踪吗?
答案 1 :(得分:0)
JBossDeveloper论坛中的答案就是问题的答案:
Remote JMS queue in JBoss AS 7.1
不会显示Netty配置的完整工作示例,使两个节点交换消息,但对理解这个概念非常有帮助。