即使在http中我也无法使其工作。
我遵循了在 Wildfly 和 HornetQ 网站上找到的所有文档。
我将standalone.xml 配置为以下更重要的摘录:
<subsystem xmlns="urn:jboss:domain:messaging:2.0">
<hornetq-server>
<journal-file-size>102400</journal-file-size>
<connectors>
<http-connector name="http-connector" socket-binding="http">
<param key="http-upgrade-endpoint" value="http-acceptor"/>
</http-connector>
<http-connector name="http-connector-throughput" socket-binding="http">
<param key="http-upgrade-endpoint" value="http-acceptor-throughput"/>
<param key="batch-delay" value="50"/>
</http-connector>
</connectors>
<acceptors>
<http-acceptor http-listener="default" name="http-acceptor"/>
<http-acceptor http-listener="default" name="http-acceptor-throughput">
<param key="batch-delay" value="50"/>
<param key="direct-deliver" value="false"/>
</http-acceptor>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="send" roles="JMSRole"/>
<permission type="consume" roles="JMSRole"/>
<permission type="createNonDurableQueue" roles="JMSRole"/>
<permission type="deleteNonDurableQueue" roles="JMSRole"/>
</security-setting>
</security-settings>
<jms-connection-factories>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="http-connector"/>
</connectors>
<entries>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
<ha>true</ha>
<block-on-acknowledge>true</block-on-acknowledge>
<retry-interval>1000</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<reconnect-attempts>-1</reconnect-attempts>
</connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="JMSOrderDownloadPage">
<entry name="java:/jms/queue/JMSOrderDownloadPage"/>
<durable>true</durable>
<entry name="java:jboss/exported/jms/queue/JMSOrderDownloadPage"/>
</jms-queue>
<jms-queue name="DLQ">
<entry name="java:/jms/queue/DLQ"/>
<durable>true</durable>
</jms-queue>
</jms-destinations>
</hornetq-server>
</subsystem>
我尝试运行下面的代码。一切正常,但我要求 connectionFactory 创建一个新连接。
HornetQConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
MessageProducer producer = null;
MessageConsumer consumer = null;
Destination destination = null;
TextMessage message = null;
Context context = null;
try {
// Set up the context for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://www.xyz.com:8080");
env.put(Context.SECURITY_PRINCIPAL, "jmsuser");
env.put(Context.SECURITY_CREDENTIALS, "pass1");
env.put("jboss.naming.client.ejb.context", true);
context = new InitialContext(env);
connectionFactory = (HornetQConnectionFactory) context.lookup("jms/RemoteConnectionFactory"); //The lockup function correctly. Including authentication.
destination = (Destination) context.lookup("java:/jms/queue/JMSOrderDownloadPage");
connection = connectionFactory.createConnection("jmsuser", "pass1"); //At this time the error occurs following below, after the code.
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
connection.start();
int count = Integer.parseInt("1");
String content = System.getProperty("message.content", "Hello, World!");
for (int i = 0; i < count; i++) {
message = session.createTextMessage(content);
producer.send(message);
}
} catch (Exception e) {
e.printStackTrace();
}
StackTrace 是:
javax.jms.JMSException:无法在 org.hornetq.jms.client.HornetQConnectionFactory.createConnection(HornetQConnectionFactory.java:112) 的 org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:673) 创建会话工厂br.com.voelivre.finder.queue.search.alert.Start.main(Start.java:106)原因:HornetQNotConnectedException[errorType=NOT_CONNECTED message=HQ119007:无法连接到服务器。尝试了所有可用的服务器。] 在 org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:905) 在 org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:669) ...还有 2 个
我真的很感激任何帮助。