|
| 1 | +@GrabResolver(name = 'rabbitmq-bintray', root = 'http://dl.bintray.com/rabbitmq/maven') |
| 2 | +@GrabResolver(name = 'rabbitmq-bintray-milestones', root = 'http://dl.bintray.com/rabbitmq/maven-milestones') |
| 3 | +@Grab(group = 'com.rabbitmq', module = 'amqp-client', version = "${version}") |
| 4 | +@Grab(group = 'org.slf4j', module = 'slf4j-simple', version = '1.7.25') |
| 5 | +import com.rabbitmq.client.AMQP |
| 6 | +import com.rabbitmq.client.Channel |
| 7 | +import com.rabbitmq.client.ConnectionFactory |
| 8 | +import com.rabbitmq.client.DefaultConsumer |
| 9 | +import com.rabbitmq.client.Envelope |
| 10 | +import org.slf4j.LoggerFactory |
| 11 | + |
| 12 | +import java.util.concurrent.CountDownLatch |
| 13 | +import java.util.concurrent.TimeUnit |
| 14 | + |
| 15 | +def connection = new ConnectionFactory().newConnection() |
| 16 | +try { |
| 17 | + Channel ch = connection.createChannel() |
| 18 | + def queue = ch.queueDeclare().getQueue() |
| 19 | + CountDownLatch latch = new CountDownLatch(1); |
| 20 | + ch.basicConsume(queue, true, new DefaultConsumer(ch) { |
| 21 | + @Override |
| 22 | + void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { |
| 23 | + latch.countDown() |
| 24 | + } |
| 25 | + }) |
| 26 | + ch.basicPublish("", queue, null, "test".getBytes()) |
| 27 | + def received = latch.await(5, TimeUnit.SECONDS) |
| 28 | + if (!received) |
| 29 | + throw new IllegalStateException("Didn't receive message in 5 seconds") |
| 30 | + LoggerFactory.getLogger("rabbitmq").info("Test succeeded") |
| 31 | + System.exit 0 |
| 32 | +} catch (Exception e) { |
| 33 | + LoggerFactory.getLogger("rabbitmq").info("Test failed", e) |
| 34 | + System.exit 1 |
| 35 | +} |
0 commit comments