简体   繁体   English

JMS + WildFly 8.2.0-从远程jms队列读取

[英]JMS + WildFly 8.2.0 - Reading from remote jms queue

I'm trying to read messages from a remote jms queue located on remote server, also on WildFly 8.2.0. 我正在尝试从同样位于WildFly 8.2.0上的远程服务器上的远程jms队列中读取消息。 The remote queue name defined on remote server is "java:jboss/exported/jms/queue/grinderRemote". 在远程服务器上定义的远程队列名称是“ java:jboss / exported / jms / queue / grinderRemote”。

I defined a queue on the read server with the same name, but I'm not sure that it's correct. 我在读取服务器上用相同的名称定义了一个队列,但是我不确定它是否正确。

For read message I created a Dynamic Web Project with MDB class. 对于阅读消息,我创建了带有MDB类的动态Web项目。 The code is below 代码如下

package it.vr.pms;

import java.util.logging.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;


@MessageDriven(name = "ReadJMS1", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "/exported/jms/queue/grinderRemote"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), 
    @ActivationConfigProperty(propertyName = "user", propertyValue = "jmsuser"), 
    @ActivationConfigProperty(propertyName = "password", propertyValue = "********"),
    //@ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),
    //@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),
    @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=http-remoting://192.168.5.124;port=8080")})
public class ReadJMS1 implements MessageListener {

    private final static Logger LOGGER = Logger.getLogger(ReadJMS1.class.toString());


    public void onMessage(Message rcvMessage) {
        TextMessage msg = null;
        try {
            if (rcvMessage instanceof TextMessage) {
                msg = (TextMessage) rcvMessage;
                System.out.println("Received Message from queue: " + msg.getText());
            } else {
                System.out.println("Message of wrong type: " + rcvMessage.getClass().getName());
            }
        } catch (JMSException e) {
            throw new RuntimeException(e);
        }
    }
}

The "reader" server log is the following: “阅读器”服务器日志如下:

10:26:10,273 INFO  [org.hornetq.ra] (default-threads - 1) HQ151000: awaiting topic/queue creation /exported/jms/queue/grinderRemote
10:26:10,336 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-4) JBAS017534: Registered web context: /TestJMSReceive
10:26:10,492 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 31) JBAS018559: Deployed "TestJMSReceiveEAR.ear" (runtime-name : "TestJMSReceiveEAR.ear")
10:26:10,836 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://0.0.0.0:9990/management
10:26:10,836 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://0.0.0.0:9990
10:26:10,836 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.0.Final "Tweek" started in 9312ms - Started 326 of 386 services (112 services are lazy, passive or on-demand)
10:26:12,304 INFO  [org.hornetq.ra] (default-threads - 1) HQ151001: Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@48b7ee22 destination=/exported/jms/queue/grinderRemote destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=jmsuser password=**** maxSession=15)

I can't understand where I'm wrong. 我不明白我哪里错了。 I also tried using the commented @ActivationConfigProperty but the result was the same... 我也尝试使用注释的@ActivationConfigProperty,但是结果是相同的...

Any help is appreciated. 任何帮助表示赞赏。

Thanks 谢谢

EDIT 编辑

I did the configuration suggested by apocalypz but the error is the following now: 我做了apocalypz建议的配置,但现在错误如下:

15:25:47,116 INFO  [org.jboss.as.ejb3] (MSC service thread 1-1) JBAS014142: Started message driven bean 'ReadJMS1' with 'hornetq-ra.rar' resource adapter
15:25:47,163 WARN  [org.hornetq.ra] (default-threads - 1) HQ152005: Failure in HornetQ activation org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@71996bda destination=queue/LocalServer1Q destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15): javax.naming.NameNotFoundException: jms/RemoteConnectionFactory -- service jboss.naming.context.java.jms.RemoteConnectionFactory

Seems it tries to use resource adapter hornetq-ra instead of RemoteConnectionFactory. 似乎它尝试使用资源适配器hornetq-ra而不是RemoteConnectionFactory。 Or it cannot found RemoteConnectionFactory on the other server? 还是在另一台服务器上找不到RemoteConnectionFactory?

You need to configure RemoteConnectionFactory on server with MDB (inside wildfly config you are currently using, eg standalone-full.xml), then set it via 'connectionFactoryLookup' property. 您需要在带有MDB的服务器上配置RemoteConnectionFactory(在当前使用的wildfly配置中,例如standalone-full.xml),然后通过“ connectionFactoryLookup”属性进行设置。 Destination does not need to be in jboss/exported ns. 目标不必位于jboss / exports ns中。

@MessageDriven(name = "RemoteQueueConsumer", 
activationConfig = { 
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/jms/queue/RemoteQueue"),
    @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "java:jboss/jms/RemoteConnectionFactory"),              
    @ActivationConfigProperty(propertyName = "user", propertyValue = "user1"),
    @ActivationConfigProperty(propertyName = "password", propertyValue = "pwd.123"),  
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "messageType=testMessage") 
})

For RemoteConnectionFactory configuration you must point ConnectionFactory to Connector, which has reference to outbound-socket-binding. 对于RemoteConnectionFactory配置,必须将ConnectionFactory指向连接器,该连接器引用了outbound-socket-binding。

In case someone need other solution using Wildfly (Jboss), This post give another example 如果有人需要使用Wildfly(Jboss)的其他解决方案,本文将举另一个例子

@ResoucerAdapter @ResoucerAdapter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM