|
| 1 | +@GrabResolver(name = 'ossrh-staging', root = 'https://oss.sonatype.org/content/groups/staging/') |
| 2 | +@GrabResolver(name = 'rabbitmq-packagecloud-milestones', root = 'https://packagecloud.io/rabbitmq/maven-milestones/maven2') |
| 3 | +@Grab(group = 'com.rabbitmq', module = 'stream-client', version = "${version}") |
| 4 | +@Grab(group = 'org.slf4j', module = 'slf4j-simple', version = '1.7.32') |
| 5 | +import com.rabbitmq.stream.ConfirmationHandler |
| 6 | +import com.rabbitmq.stream.ConfirmationStatus |
| 7 | +import com.rabbitmq.stream.Environment |
| 8 | +import com.rabbitmq.stream.Message |
| 9 | +import com.rabbitmq.stream.MessageHandler |
| 10 | +import com.rabbitmq.stream.OffsetSpecification |
| 11 | +import org.slf4j.LoggerFactory |
| 12 | + |
| 13 | +import java.nio.charset.StandardCharsets |
| 14 | +import java.util.concurrent.CountDownLatch |
| 15 | +import java.util.concurrent.TimeUnit |
| 16 | + |
| 17 | +def logger = LoggerFactory.getLogger("rabbitmq") |
| 18 | +logger.info("connecting") |
| 19 | +def env = Environment.builder().build() |
| 20 | +logger.info("connected") |
| 21 | +def s = "sanity-check-stream" |
| 22 | +env.streamCreator().stream(s).create() |
| 23 | +logger.info("test stream created") |
| 24 | +try { |
| 25 | + def publishLatch = new CountDownLatch(1) |
| 26 | + def producer = env.producerBuilder().stream(s).build() |
| 27 | + logger.info("producer created") |
| 28 | + producer.send(producer.messageBuilder().addData("".getBytes(StandardCharsets.UTF_8)).build(), |
| 29 | + new ConfirmationHandler() { |
| 30 | + @Override |
| 31 | + void handle(ConfirmationStatus confirmationStatus) { |
| 32 | + publishLatch.countDown() |
| 33 | + } |
| 34 | + } |
| 35 | + ) |
| 36 | + |
| 37 | + logger.info("waiting for publish confirm") |
| 38 | + |
| 39 | + def done = publishLatch.await(5, TimeUnit.SECONDS) |
| 40 | + if (!done) { |
| 41 | + throw new IllegalStateException("Did not receive publish confirm") |
| 42 | + } |
| 43 | + |
| 44 | + logger.info("got publish confirm") |
| 45 | + |
| 46 | + def consumeLatch = new CountDownLatch(1) |
| 47 | + env.consumerBuilder() |
| 48 | + .stream(s) |
| 49 | + .offset(OffsetSpecification.first()) |
| 50 | + .messageHandler(new MessageHandler() { |
| 51 | + @Override |
| 52 | + void handle(MessageHandler.Context context, Message message) { |
| 53 | + consumeLatch.countDown() |
| 54 | + } |
| 55 | + }).build() |
| 56 | + |
| 57 | + logger.info("created consumer, waiting for message") |
| 58 | + |
| 59 | + done = consumeLatch.await(5, TimeUnit.SECONDS) |
| 60 | + if (!done) { |
| 61 | + throw new IllegalStateException("Did not receive message") |
| 62 | + } |
| 63 | + |
| 64 | + logger.info("got message") |
| 65 | + |
| 66 | + logger.info("Test succeeded with Stream Client {}", |
| 67 | + Environment.package.getImplementationVersion()) |
| 68 | + System.exit 0 |
| 69 | +} catch (Exception e) { |
| 70 | + logger.info("Test failed with Stream Client {}", |
| 71 | + Environment.package.getImplementationVersion(), e) |
| 72 | + System.exit 1 |
| 73 | +} finally { |
| 74 | + env.deleteStream(s) |
| 75 | + env.close(); |
| 76 | +} |
0 commit comments