I create java app that uses message driven bean(MDB) to get message from topic apache apollo through resource adapter activeMq 5.10 in glassfish. When i use apache ActiveMQ, it works fine but not work with apache apollo. I use mqtt to send message with topic a and mqtt to listen at that topic and gets the message. But when i use MDB to listen , it can't get any message. I see apollo console, tab virtual host -> topic. I click the topic that use to send and receive message. That topic has consumer and producer, "Enqueued: 2 items / 2.72 kb" but consumer "Transfers = 0". I don't know how to do MDB work with 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>
Code to publish message:
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";
}
}
Even if Apollo has a great modern core, it does not have all features of ActiveMQ. While ActiveMQ supports mixing wire protocols between producers/consumers - Apollo does not. If you switch to Apollo, you much also switch to consuming using MQTT in your case.