使用消息驱动的bean从主题apache apollo

时间:2015-06-13 06:24:06

标签: java activemq apollo

我使用消息驱动bean(MDB)创建java应用程序,通过glassfish中的资源适配器activeMq 5.10从主题apache apollo获取消息。当我使用apache ActiveMQ时,它工作正常,但无法使用apache apollo。我使用mqtt发送带有主题a和mqtt的消息来监听该主题并获取消息。但是,当我使用MDB收听时,它无法获得任何消息。我看到apollo console,tab virtual host - >话题。我单击用于发送和接收消息的主题。该主题有消费者和制作人,“入队:2项/ 2.72 kb”,但消费者“转移= 0”。我不知道如何让MDB与Apollo合作。

apollo.xml

<broker xmlns="http://activemq.apache.org/schema/activemq/apollo">
  <notes>
       The default configuration with tls/ssl enabled.
  </notes>
  <log_category console="console" `enter code here`security="security"connection="connection"audit="audit"/>
  <authentication domain="apollo"/>
  <!-- Give admins full access -->
  <access_rule allow="admins" action="*"/>
  <access_rule allow="*" action="*"/> 
  <virtual_host id="benchmark-broker">
     <host_name>benchmark-broker</host_name>
     <host_name>localhost</host_name>
     <host_name>127.0.0.1</host_name> 
     <authentication enabled="false"/>
     <topic slow_consumer_policy="block" >
       <subscription tail_buffer="4k"/>
     </topic>
  </virtual_host>
  <web_admin bind="http://0.0.0.0:9022"/>
  <web_admin bind="https://127.0.0.1:61681"/>
  <connector id="tcpMqtt" bind="tcp://0.0.0.0:7521" connection_limit="60000">
      <mqtt max_message_length="104857600"  />
  </connector>
 <connector id="tcpOpenwire" bind="tcp://0.0.0.0:9021" connection_limit="60000">
     <openwire tight_encoding="false" tcp_no_delay="true"/>
 </connector>
</broker>

发布消息的代码:

    String user = env("APOLLO_USER", "admin");
    String password = env("APOLLO_PASSWORD", "password");
    String host = env("APOLLO_HOST", "192.168.0.54");
    int port = Integer.parseInt(env("APOLLO_PORT", "7521"));
    final String destination = arg(args, 0, "cuongdm17");
    int messages = 1;
    String body = "test";

    MQTT mqtt = new MQTT();
    mqtt.setHost(host, port);
    mqtt.setUserName(user);
    mqtt.setPassword(password);

    FutureConnection connection = mqtt.futureConnection();
    connection.connect().await();
    final LinkedList<Future<Void>> queue = new LinkedList<Future<Void>>();
    UTF8Buffer topic = new UTF8Buffer(destination);
    for (int i = 1; i <= messages; i++) {
        queue.add(connection.publish(topic, msg, QoS.AT_LEAST_ONCE, false));
    }

MDB:

@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "cuongdm17")
})
public class Cuongdm17 extends AmiAbstractMQTTProcessor implements MessageListener, Serializable {

static final Logger logger = Logger.getLogger(AmiMonitorProcessor.class.getName());

public Cuongdm17() {
}

@Override
protected Logger getLogger() {
    return logger;
}

/**
 * Handler MQTT (already transcript to JMS) messages from DCU Device
 *
 * @param message
 */
@Override
public void onMessage(Message message) {
    try {
        info("cuongdm17");
    } catch (Exception e) {
        error("Error when processing onMessage, error message=" + e.getMessage() + ", message trace=" + message, e);
    }
}

@Override
protected void receiveMessage(MQTTPayloadData payload) throws Exception {
    info("cuongdm17");
}

@Override
public String toString() {
    return "Current-Info Processor";
}
}

1 个答案:

答案 0 :(得分:0)

即使Apollo拥有出色的现代核心,它也没有ActiveMQ的所有功能。虽然ActiveMQ支持生产者/消费者之间的混合线协议 - 但Apollo却没有。如果你切换到Apollo,你也可以在你的情况下切换到使用MQTT消费。