1

我创建了 java 应用程序,它使用消息驱动 bean(MDB) 通过 glassfish 中的资源适配器 activeMq 5.10 从主题 apache apollo 获取消息。当我使用 apache ActiveMQ 时,它可以正常工作,但不能与 apache apollo 一起使用。我使用 mqtt 发送带有主题 a 的消息,并使用 mqtt 来监听该主题并获取消息。但是当我使用 MDB 收听时,它无法收到任何消息。我看到 apollo 控制台,选项卡虚拟主机 -> 主题。我单击用于发送和接收消息的主题。该主题有消费者和生产者,“入队:2 个项目 / 2.72 kb”,但消费者“转移 = 0”。我不知道如何使用 Apollo 进行 MDB 工作。

阿波罗.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));
    }

多边开发银行:

@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";
}
}
4

1 回答 1

0

即使 Apollo 有一个伟大的现代核心,它也不具备 ActiveMQ 的所有特性。虽然 ActiveMQ 支持在生产者/消费者之间混合有线协议,但 Apollo 不支持。如果您切换到 Apollo,在您的情况下,您也会切换到使用 MQTT 进行消费。

于 2015-06-13T09:10:09.777 回答