1

メッセージ駆動型 Bean(MDB) を使用して、グラスフィッシュのリソース アダプター activeMq 5.10 を介してトピック Apache apollo からメッセージを取得する Java アプリを作成します。apache ActiveMQ を使用すると正常に動作しますが、apache apollo では動作しません。mqtt を使用してトピック a のメッセージを送信し、mqtt を使用してそのトピックをリッスンし、メッセージを取得します。しかし、MDB を使用してリッスンすると、メッセージを取得できません。apollo コンソール、タブの仮想ホスト -> トピックが表示されます。メッセージの送受信に使用するトピックをクリックします。そのトピックにはコンシューマーとプロデューサーがあり、「エンキュー: 2 アイテム / 2.72 kb」ですが、コンシューマーは「Transfers = 0」です。Apollo で MDB を操作する方法がわかりません。

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

1 に答える 1

0

Apollo が優れた最新のコアを備えていたとしても、ActiveMQ のすべての機能を備えているわけではありません。ActiveMQ はプロデューサー/コンシューマー間のワイヤ プロトコルの混在をサポートしていますが、Apollo はサポートしていません。Apollo に切り替えると、MQTT を使用して消費するようになります。

于 2015-06-13T09:10:09.777 に答える