|
| 1 | +///usr/bin/env jbang "$0" "$@" ; exit $? |
| 2 | +//REPOS mavencentral,ossrh-staging=https://oss.sonatype.org/content/groups/staging/,rabbitmq-packagecloud-milestones=https://packagecloud.io/rabbitmq/maven-milestones/maven2 |
| 3 | +//DEPS com.rabbitmq.jms:rabbitmq-jms:2.5.0.RC1 |
| 4 | +//DEPS org.slf4j:slf4j-simple:1.7.36 |
| 5 | + |
| 6 | +import com.rabbitmq.jms.admin.RMQConnectionFactory; |
| 7 | +import javax.jms.DeliveryMode; |
| 8 | +import javax.jms.Message; |
| 9 | +import javax.jms.Queue; |
| 10 | +import javax.jms.QueueConnection; |
| 11 | +import javax.jms.QueueReceiver; |
| 12 | +import javax.jms.QueueSender; |
| 13 | +import javax.jms.QueueSession; |
| 14 | +import javax.jms.Session; |
| 15 | +import org.slf4j.LoggerFactory; |
| 16 | + |
| 17 | +public class SanityCheck { |
| 18 | + |
| 19 | + public static void main(String[] args) throws Exception { |
| 20 | + QueueConnection connection = null; |
| 21 | + try { |
| 22 | + connection = (QueueConnection) new RMQConnectionFactory().createConnection(); |
| 23 | + connection.start(); |
| 24 | + QueueSession queueSession = connection.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE); |
| 25 | + Queue queue = queueSession.createTemporaryQueue(); |
| 26 | + |
| 27 | + QueueSender queueSender = queueSession.createSender(queue); |
| 28 | + queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT); |
| 29 | + Message message = queueSession.createTextMessage("Hello"); |
| 30 | + queueSender.send(message); |
| 31 | + |
| 32 | + QueueReceiver queueReceiver = queueSession.createReceiver(queue); |
| 33 | + message = queueReceiver.receive(5000); |
| 34 | + if (message == null) throw new IllegalStateException("Didn't receive message in 5 seconds"); |
| 35 | + LoggerFactory.getLogger("rabbitmq") |
| 36 | + .info( |
| 37 | + "Test succeeded with JMS Client {}", |
| 38 | + RMQConnectionFactory.class.getPackage().getImplementationVersion()); |
| 39 | + System.exit(0); |
| 40 | + } catch (Exception e) { |
| 41 | + LoggerFactory.getLogger("rabbitmq") |
| 42 | + .info( |
| 43 | + "Test failed with JMS Client {}", |
| 44 | + RMQConnectionFactory.class.getPackage().getImplementationVersion(), |
| 45 | + e); |
| 46 | + if (connection != null) { |
| 47 | + connection.close(); |
| 48 | + } |
| 49 | + System.exit(1); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
0 commit comments