我试图向JBoss EAP 7.2中嵌入的远程ActiveMQ Artemis队列发送JMS消息。我在《独立完整》中定义了以下内容。xml:
<subsystem xmlns="urn:jboss:domain:messaging-activemq:4.0">
<server name="default">
<journal pool-files="10"/>
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<remote-connector name="ImportantMessages-remote" socket-binding="ImportantMessages-remote"/>
<in-vm-connector name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-connector>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-acceptor>
<jms-queue name="TestQueue" entries="java:/jms/queue/TestQueue"/>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
<pooled-connection-factory name="ImportantMessages-remote" entries="java:/jms/remoteIM" connectors="ImportantMessages-remote"/>
</server>
</subsystem>
<subsystem xmlns="urn:wildfly:microprofile-config-smallrye:1.0"/>
<subsystem xmlns="urn:wildfly:microprofile-health-smallrye:1.0" security-enabled="false"/>
<subsystem xmlns="urn:wildfly:microprofile-opentracing-smallrye:1.0"/>
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<external-context name="java:global/remoteContext" module="org.apache.activemq.artemis" class="javax.naming.InitialContext">
<environment>
<property name="java.naming.factory.initial" value="org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory"/>
<property name="java.naming.provider.url" value="tcp://127.0.0.1:61616"/>
<property name="queue.ImportantMessages" value="ImportantMessages"/>
</environment>
</external-context>
<lookup name="java:/ImportantMessages" lookup="java:global/remoteContext/ImportantMessages"/>
</bindings>
<remote-naming/>
</subsystem>
以下是我的客户程序:
public void sendObjectMessage() {
Properties initialProperties = new Properties();
initialProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
initialProperties.put(InitialContext.PROVIDER_URL, "tcp://127.0.0.1:61616");
try {
context = new InitialContext(initialProperties);
factory = (QueueConnectionFactory) context.lookup("java:/jms/remoteIM");
destination = (Queue) context.lookup("java:global/remoteContext/ImportantMessages");
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
EventMessage eventMessage = new EventMessage("1", "Message from FirstClient");
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(eventMessage);
connection.start();
producer.send(objectMessage);
System.out.println(this.getClass().getName() + "has sent a message : " + eventMessage);
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
} finally {
if (context != null) {
try {
context.close();
} catch (NamingException ex) {
ex.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (JMSException ex) {
ex.printStackTrace();
}
}
}
}
我得到以下例外:
javax.naming.NamingException: scheme java not recognized
at org.apache.activemq.artemis.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:222)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.example.demo.sender.FirstClient.sendObjectMessage(FirstClient.java:41)
at com.example.demo.controller.MessagingController.sendMessage(MessagingController.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:888)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
有人能告诉我我做错了什么吗?
为了向JBoss EAP中嵌入的远程ActiveMQ Artemis队列发送JMS消息,可以使用默认的standalone full。xml
。您不需要设置远程连接器、池连接工厂或远程绑定。您只需使用JBoss EAP JNDI上下文从客户端查找jms/RemoteConnectionFactory
。需要明确的是,当ActiveMQ Artemis嵌入JBoss EAP时,远程客户端使用JBoss EAP JNDI上下文,而不是ActiveMQ Artemis JNDI上下文,因为EAP本身负责所有JNDI操作。
您的客户端正在使用ActiveMQ Artemis JNDI上下文:
initialProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
initialProperties.put(InitialContext.PROVIDER_URL, "tcp://127.0.0.1:61616");
这是不正确的。你应该用这个代替:
initialProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
initialProperties.put(InitialContext.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
注意:你也可以使用org。jboss。命名。遥控器。客户InitialContextFactory
,因为该类也随JBoss EAP 7.2一起提供。然而,这个类实际上是为了向后兼容遗留客户端。
然后,您的客户端正在尝试查找您在standalone-full.xml
中配置的pooled-Connection-Factory
:
factory = (QueueConnectionFactory) context.lookup("java:/jms/remoteIM");
这也是不正确的。池连接工厂
只能由与JBoss EAP在同一JVM中运行的客户端使用(例如,需要发送消息的MDB)。你不能简单地从远程客户端查找它,然后期望得到池。事情不是这样的。你应该这样做:
factory = (QueueConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
这将使用standalone-full.xml
中的默认连接工厂。
然后,您正在查找一个消息子系统中甚至没有定义的队列(即java:global/remoteContext/ImportantMessages
)。出于某种原因,您显然在外部上下文中配置了它。这对EAP来说是错误的。您应该在
独立完整版中定义这一点。xml
:
<jms-queue name="ImportantMessages" entries="java:jboss/exported/ImportantMessages"/>
然后在你的客户中使用:
destination = (Queue) context.lookup("ImportantMessages");
最终,这就是您的消息子系统在
独立版中的完整功能。xml
应该如下所示:
xml prettyprint-override"><subsystem xmlns="urn:jboss:domain:messaging-activemq:4.0">
<server name="default">
<journal pool-files="10"/>
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<in-vm-connector name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-connector>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0">
<param name="buffer-pooling" value="false"/>
</in-vm-acceptor>
<jms-queue name="ImportantMessages" entries="java:jboss/exported/ImportantMessages"/>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
</server>
</subsystem>
您不需要配置的
外部上下文
。
最后,你的客户最终应该是这样的:
public void sendObjectMessage() {
Properties initialProperties = new Properties();
initialProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
initialProperties.put(InitialContext.PROVIDER_URL, "http-remoting://127.0.0.1:8080");
try {
context = new InitialContext(initialProperties);
factory = (QueueConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
destination = (Queue) context.lookup("ImportantMessages");
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
EventMessage eventMessage = new EventMessage("1", "Message from FirstClient");
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(eventMessage);
connection.start();
producer.send(objectMessage);
System.out.println(this.getClass().getName() + "has sent a message : " + eventMessage);
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
} finally {
if (context != null) {
try {
context.close();
} catch (NamingException ex) {
ex.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (JMSException ex) {
ex.printStackTrace();
}
}
}
}
JBoss EAP提供了一系列“快速入门”应用程序来演示如何使用其功能。以下是JMS“Hello World”快速入门,您可能会发现它对参考很有用。
如果您正在使用Maven构建客户端应用程序,那么这就是您应该使用的依赖项:
<dependency>
<groupId>org.jboss.eap</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<type>pom</type>
</dependency>
另外,请记住,JBoss EAP 7.2中嵌入的ActiveMQ Artemis在默认情况下是安全的,因此您需要禁用消息子系统中的安全性(例如使用
我试图将一个Wildfly13实例连接到一个独立的Artemis ActiveMQ,从它生成和使用消息。因此,我遵循了Wildfly13文档和Artemis ActiveMQ文档的相关部分。此外,我尝试使用本教程,并使用JMS2.0Simplified-API对其进行了一些定制。 当我向/Produce发送有效载荷时,不会引发异常。所以我相信JNDI有一个问题。我已经用Wireshark监视了正在
本文向大家介绍C#向无窗口的进程发送消息,包括了C#向无窗口的进程发送消息的使用技巧和注意事项,需要的朋友参考一下 注:本文适用.net2.0+的winform程序 一个winform程序,我希望它不能多开,那么在用户启动第二个实例的时候,作为第二个实例来说,大概可以有这么几种做法: 1.弹个窗告知用户【程序已运行】之类,用户点击弹窗后,退出自身 2.什么都不做,默默退出自身 3.让已运行的第一个
我的代码如下:, 从服务器通知FCM(C#) 我对上述要求的答复 {"multicast_id":5002368547300,"成功": 1,"失败": 0,"canonical_ids": 0,"结果":[{"message_id":"0:14200031 c4rrr5787蛋"}]} 我假设一旦FCM收到新的通知,它将把这些通知推送到各自的Android设备。 但对我来说,它不起作用。
我正在为android中的knx模块开发一个串口应用程序。我可以向knx modulde发送和接收赞扬。当从serialport接收到消息时,我想更改ui(例如按钮属性)。我用处理程序试过了,但我无法更改ui。帮我一把。 @覆盖公共空OnSerialsData(最终字节[]缓冲区,最终int大小){......} 它是我的串行端口侦听器函数,调用insine ReadThread。此线程从我的活动
如何修复ProbableAuthenticationError? 主机是Debian7和Python 2.7.3和pika 0.9.14,来宾是Ubuntu 15.04和rabbitmq-server 3.4.3-2
问题内容: 我需要向程序中运行的每个线程发送信息,并且每个线程都必须处理该信息。 我无法使用常规队列来执行此操作,因为那样一来,一旦一个线程从队列中删除了数据,所有其他线程将无法再看到它。 实现此目标的最佳方法是什么? 问题答案: 一种方法是在 每个 线程中都有一个队列,广播信息的功能负责将消息插入每个线程的队列中。 例如,这类似于消息队列在Windows中的工作方式。每个执行GUI操作的线程都有