0
votes

So I am using ActiveMQ as a MQTT broker like this:

TransportConnector mqtt = new TransportConnector();
mqtt.setName(mqttBrokerConfig.getBrokerName());
URI uri = new URI("mqtt://some ip");
mqtt.setUri(uri);
final BrokerService broker = new BrokerService();
broker.setUseJmx(false);        // Disable JMX for secure purpose
broker.setPersistent(mqttBrokerConfig.getPersistence());
broker.setAdvisorySupport(mqttBrokerConfig.getAdvisorySupport());
if(mqttBrokerConfig.getEnableLogin()) {
    SimpleAuthenticationPlugin authenticationPlugin = loadLogins();
    broker.setPlugins(new BrokerPlugin[]{authenticationPlugin});
}
broker.setUseShutdownHook(true);
broker.addConnector(mqtt);

I need to accept MQTT message from outside, read the message from the broker, and send it to Kafka. Right now I in the same JVM I created a MQTT client, and connect the broker through 127.0.0.1. Going through the internal network still has some overhead, and the connection could be lost sometimes.

Since the client is in the same JVM as the broker is there a way to read the MQTT messages directly without going through the network? If ActiveMQ does not support such feature is there another java MQTT broker that support it?

1

1 Answers

0
votes

I believe the VM transport is what you want. If your client uses the VM transport that should eliminate any overhead incurred from going through a normal network connection.

In order to use the VM transport you'll need to use the OpenWire JMS client that ships with ActiveMQ. Your remote MQTT client(s) can send messages to the embedded ActiveMQ broker and your local clients in the same VM can then receive those messages.

Other protocol clients (e.g. MQTT, AMQP, STOMP, etc.) will not be able to use the VM transport as it requires ActiveMQ-specific integration.