从 servlet 向 HornetQ 队列添加一个项目

Adding an item to a HornetQ queue from a servlet

我有一个构建为 war 文件并部署到 JBOSS 服务器的项目。 JBOSS 服务器的 standalone-full-ha.xml 文件配置为创建多个队列。 war 文件使用 Spring 注册一个 class 来监听这些队列,并处理它收到的消息。通常将消息放入队列的应用程序是由另一个供应商编写的;我不知道该代码是什么样的。但是,出于测试目的,我需要能够将消息添加到我的开发环境中的队列中。

我写了一个小的 servlet 并将它添加到 war 来尝试这个测试。但是,调用 servlet 时出现异常:

13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1) javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeExcept
ion: Operation failed with status WAITING]
13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121
)
13:54:12,211 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.InitialContext.init(InitialContext.java:242)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.naming.InitialContext.<init>(InitialContext.java:216)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at com.me.me.servlets.SingleFileImportServlet.doGet(SingleFileImportServlet.java:75)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
13:54:12,226 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.ja
va:67)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.j
ava:48)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java
:169)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
13:54:12,242 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at java.lang.Thread.run(Thread.java:745)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1) Caused by: java.lang.RuntimeException: Operation failed with status WAITING
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:89)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFacto
ry.java:166)
13:54:12,257 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.jav
a:139)
13:54:12,273 ERROR [stderr] (http-/0.0.0.0:8080-1)      at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104
)
13:54:12,273 ERROR [stderr] (http-/0.0.0.0:8080-1)      ... 22 more

这是第 75 行之前和之前的代码(在堆栈跟踪中引用)。它是从以前的测试中借用的,所以我有理由相信它应该有效。

Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

properties.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");
properties.put(Context.SECURITY_PRINCIPAL, "user");
properties.put(Context.SECURITY_CREDENTIALS, "pwd");

ConnectionFactory connectionFactory = null;
Destination destination = null;

try {
    Context context = new InitialContext(properties);

所以有几个问题: 1) 你能看到我需要在此 servlet 中做哪些不同的事情来连接到队列吗? 2) 我有 "remote://" 的其他有效值是否有文档? 3) 据推测,我拥有 4447 的端口需要与 JBOSS 配置中的某些内容相匹配 - 是否有相关文档?

谢谢

仅当从服务器外部执行 JNDI 查找时才需要传递给 InitialContext 的工厂、URL 和安全原则。

如果包含您的测试 servlet 的 war 部署在配置了队列的同一台服务器中,那么您应该能够实例化一个新的 InitialContext() 而无需任何属性来执行查找针对本地 JDNI 实例。

try {
    Context context = new InitialContext();