Created
February 18, 2022 12:54
-
-
Save io7m/e681abb2ba0bb12c64aca7f223d1ea87 to your computer and use it in GitHub Desktop.
example2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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