Skip to content

Instantly share code, notes, and snippets.

@io7m
Created February 18, 2022 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io7m/e681abb2ba0bb12c64aca7f223d1ea87 to your computer and use it in GitHub Desktop.
Save io7m/e681abb2ba0bb12c64aca7f223d1ea87 to your computer and use it in GitHub Desktop.
example2.java
package com.io7m.jmstest;
import org.apache.activemq.artemis.api.core.TransportConfiguration;
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
import java.util.UUID;
import static javax.jms.Session.CLIENT_ACKNOWLEDGE;
import static org.apache.activemq.artemis.api.jms.JMSFactoryType.CF;
public final class Main
{
private Main()
{
}
public static void main(
final String[] args)
throws Exception
{
final var transportConfiguration =
new TransportConfiguration(NettyConnectorFactory.class.getName());
final var connections =
ActiveMQJMSClient.createConnectionFactoryWithoutHA(
CF,
transportConfiguration);
connections.setBrokerURL("<redacted>");
connections.setClientID(UUID.randomUUID().toString());
connections.setUser("<redacted>");
connections.setPassword("<redacted>");
while (true) {
try (final var topicConnection =
connections.createTopicConnection()) {
try (var session =
topicConnection.createTopicSession(false, CLIENT_ACKNOWLEDGE)) {
final var topic =
session.createTopic("<redacted>");
try (var subscriber = session.createSubscriber(topic)) {
topicConnection.start();
while (true) {
final var message = subscriber.receive(1_000L);
message.acknowledge();
}
}
}
} catch (final Exception e) {
// ...
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment