我正在使用Wildfly 10 AS并希望为每个客户端使用单独的JMS队列(仅针对特定客户端的双向服务器 - 客户端通信)。这是遵循此处描述的P2P场景:http://www.straub.as/java/jms/basic.html
在Wildfly 10上,我使用activeMQ,我想通过应用程序自动创建队列(以及其他所有内容,如果有更多我需要的东西)。管理任务(如添加新客户端(以及新队列))应由UI操作自动完成。
我已经找到了这个解决方案,可以通过JMX自动创建队列: https://docs.jboss.org/author/display/WFLY8/JMX+subsystem+configuration 我认为我能够采用Wildfly10( 考虑 :我必须更改用于解决activemq MBean的JMX ObjectName,并为addQueue操作添加了更多参数 - 我现在使用错误的addQueue操作吗?)
我似乎使用了错误的“addQueue”方法(即在错误的JMX对象上),或者我错过了其他的东西......我现在可以创建一个队列。队列显示在JMX控制台中。但是当我尝试发送时,我收到了一个错误。除了队列之外,我是否遗漏了创建JMS端点的内容?
使用队列时出错:
Got ConnectionFactory jms/RemoteConnectionFactory javax.naming.NameNotFoundException: jms/queue/MyNewQueue -- service jboss.naming.context.java.jboss.exported.jms.queue.MyNewQueue at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184) at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
我创建队列的代码(执行时没有错误):
String host = "localhost";
int port = 10990; // management-web port
String urlString =
System.getProperty("jmx.service.url","service:jmx:http-remoting-jmx://" + host + ":" + port);
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
String operationName="addQueue";
String name="MyNewQueue2";
boolean durable=true;
String filter="MyNewQueue";
String address="jms/queue/MyNewQueue";
ObjectName activeMQ = new ObjectName("jboss.as:subsystem=messaging-activemq,server=default");//org.apache.activemq:BrokerName=default,Type=Broker");
Object[] params = {name,durable, filter, address};
String[] sig = {"java.lang.String", "java.lang.boolean", "java.lang.String","java.lang.String",};
conn.invoke(activeMQ, operationName, params, sig);
我访问队列的代码失败(基于http://www.mastertheboss.com/jboss-server/jboss-jms/how-to-code-a-remote-jms-client-for-wildfly-8):
private String MESSAGE = "Hello, World!";
private String CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
private String DESTINATION = "jms/queue/MyNewQueue";//but works with default "jms/queue/exampleQueue";
[...]
Context namingContext = null;
JMSContext context = null;
// Set up the namingContext 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://127.0.0.1:8080");
env.put(Context.SECURITY_PRINCIPAL, "$local");
env.put(Context.SECURITY_CREDENTIALS, "$local");
namingContext = new InitialContext(env);
ConnectionFactory connectionFactory = (ConnectionFactory) namingContext
.lookup(CONNECTION_FACTORY);
System.out.println("Got ConnectionFactory " + ONNECTION_FACTORY);
Destination destination = (Destination) namingContext
.lookup(DESTINATION);
System.out.println("Got JMS Endpoint " + DESTINATION);
context = connectionFactory.createContext("internal", "internal");
context.createProducer().send(destination, MESSAGE);