use of org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder in project smallrye-reactive-messaging by smallrye.
the class AmqpSinkTest method testSinkUsingAmqpMessageAndChannelNameProperty.
@Test
@Timeout(30)
@SuppressWarnings({ "deprecation" })
public void testSinkUsingAmqpMessageAndChannelNameProperty() throws Exception {
int msgCount = 10;
String topic = UUID.randomUUID().toString();
CountDownLatch msgsReceived = new CountDownLatch(msgCount);
List<org.apache.qpid.proton.message.Message> messagesReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
AtomicReference<String> attachAddress = new AtomicReference<>("non-null-initialisation-value");
server = setupMockServerForTypeTest(messagesReceived, msgsReceived, attachAddress);
SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSinkUsingChannelName(topic, server.actualPort());
// noinspection unchecked
Multi.createFrom().range(0, 10).map(v -> AmqpMessage.<String>builder().withBody(HELLO + v).withSubject("foo").build()).subscribe((Subscriber<? super AmqpMessage<String>>) sink.build());
assertThat(msgsReceived.await(6, TimeUnit.SECONDS)).isTrue();
AtomicInteger count = new AtomicInteger();
messagesReceived.forEach(msg -> {
assertThat(msg.getAddress()).isEqualTo(topic);
assertThat(msg.getSubject()).isEqualTo("foo");
Section body = msg.getBody();
assertThat(body).isInstanceOf(AmqpValue.class);
Object payload = ((AmqpValue) body).getValue();
assertThat(HELLO + count).isEqualTo(payload);
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
// Should have used an anonymous sender link, verify null target address
assertThat(attachAddress.get()).isNull();
}
use of org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder in project smallrye-reactive-messaging by smallrye.
the class AmqpSinkTest method testSinkUsingObjectThatCannotBeSerialized.
@Test
@Timeout(30)
public void testSinkUsingObjectThatCannotBeSerialized() throws Exception {
int msgCount = 10;
AtomicInteger nack = new AtomicInteger();
CountDownLatch msgsReceived = new CountDownLatch(msgCount / 2);
List<org.apache.qpid.proton.message.Message> messagesReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
server = setupMockServerForTypeTest(messagesReceived, msgsReceived);
SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSink(UUID.randomUUID().toString(), server.actualPort());
// noinspection unchecked
Multi.createFrom().range(0, 10).map(i -> {
Person p;
if (i % 2 == 0) {
p = new Person();
p.setName(HELLO + i);
} else {
p = new Bad();
p.setName(HELLO + i);
}
return p;
}).map(p -> Message.of(p, () -> CompletableFuture.completedFuture(null), e -> {
nack.incrementAndGet();
return CompletableFuture.completedFuture(null);
})).subscribe((Subscriber<? super Message<Person>>) sink.build());
assertThat(msgsReceived.await(6, TimeUnit.SECONDS)).isTrue();
await().until(() -> nack.get() == 5);
AtomicInteger count = new AtomicInteger();
messagesReceived.forEach(msg -> {
assertThat(msg.getContentType()).isEqualTo("application/json");
Section body = msg.getBody();
assertThat(body).isInstanceOf(Data.class);
Binary bin = ((Data) body).getValue();
byte[] bytes = Binary.copy(bin).getArray();
JsonObject json = Buffer.buffer(bytes).toJsonObject();
Person p = json.mapTo(Person.class);
assertThat(p.getName()).startsWith("hello-");
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount / 2);
assertThat(nack).hasValue(5);
}
use of org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder in project smallrye-reactive-messaging by smallrye.
the class AmqpSinkTest method testOutgoingMetadata.
@SuppressWarnings("unchecked")
@Test
@Timeout(30)
public void testOutgoingMetadata() throws Exception {
String address = UUID.randomUUID().toString();
int msgCount = 10;
CountDownLatch msgsReceived = new CountDownLatch(msgCount);
List<org.apache.qpid.proton.message.Message> messagesReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
server = setupMockServerForTypeTest(messagesReceived, msgsReceived);
SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSink(address, server.actualPort());
// noinspection unchecked
Multi.createFrom().range(0, 10).map(Message::of).map(m -> m.addMetadata(OutgoingAmqpMetadata.builder().withSubject("subject").withMessageId("my-id").withReplyTo("reply-to").withReplyToGroupId("reply-to-group").withPriority((short) 6).withTtl(2000).withGroupId("group").withContentType("text/plain").withCorrelationId("correlation-" + m.getPayload()).withUserId("user").withDeliveryAnnotations("some-delivery-annotation", "da-value").withMessageAnnotations("some-msg-annotation", "ma-value").withApplicationProperties(new JsonObject().put("key", "value")).withFooter("my-trailer", "hello-footer").build())).subscribe((Subscriber<? super Message<Integer>>) sink.build());
assertThat(msgsReceived.await(6, TimeUnit.SECONDS)).isTrue();
AtomicInteger count = new AtomicInteger();
messagesReceived.forEach(msg -> {
assertThat(msg.getAddress()).isEqualTo(address);
assertThat(msg.getSubject()).isEqualTo("subject");
assertThat(msg.getMessageId()).isEqualTo("my-id");
assertThat(msg.getReplyTo()).isEqualTo("reply-to");
assertThat(msg.getReplyToGroupId()).isEqualTo("reply-to-group");
assertThat(msg.getPriority()).isEqualTo((short) 6);
assertThat(msg.getTtl()).isEqualTo(2000);
assertThat(msg.getGroupId()).isEqualTo("group");
assertThat(msg.getContentType()).isEqualTo("text/plain");
assertThat(msg.getCorrelationId()).isEqualTo("correlation-" + count.get());
assertThat(msg.isFirstAcquirer()).isFalse();
assertThat(msg.getUserId()).isEqualTo("user".getBytes(StandardCharsets.UTF_8));
assertThat(msg.getDeliveryAnnotations()).isNotNull();
assertThat(msg.getDeliveryAnnotations().getValue()).containsExactly(entry(Symbol.valueOf("some-delivery-annotation"), "da-value"));
assertThat(msg.getMessageAnnotations()).isNotNull();
assertThat(msg.getMessageAnnotations().getValue()).containsExactly(entry(Symbol.valueOf("some-msg-annotation"), "ma-value"));
assertThat(msg.getApplicationProperties()).isNotNull();
assertThat(msg.getApplicationProperties().getValue()).containsExactly(entry("key", "value"));
assertThat(msg.getFooter()).isNotNull();
// noinspection unchecked
assertThat(msg.getFooter().getValue()).containsExactly(entry("my-trailer", "hello-footer"));
Section body = msg.getBody();
assertThat(body).isInstanceOf(AmqpValue.class);
assertThat(((AmqpValue) body).getValue()).isEqualTo(count.get());
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
}
use of org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder in project smallrye-reactive-messaging by smallrye.
the class AmqpSinkTest method testOutgoingMetadataWithTtlSetOnConnector.
@SuppressWarnings("unchecked")
@Test
@Timeout(30)
public void testOutgoingMetadataWithTtlSetOnConnector() throws Exception {
String address = UUID.randomUUID().toString();
int msgCount = 10;
CountDownLatch msgsReceived = new CountDownLatch(msgCount);
List<org.apache.qpid.proton.message.Message> messagesReceived = Collections.synchronizedList(new ArrayList<>(msgCount));
server = setupMockServerForTypeTest(messagesReceived, msgsReceived);
SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSinkWithConnectorTtl(address, server.actualPort(), 3000);
// noinspection unchecked
Multi.createFrom().range(0, 10).map(Message::of).map(m -> m.addMetadata(OutgoingAmqpMetadata.builder().withSubject("subject").withMessageId("my-id").withReplyTo("reply-to").withReplyToGroupId("reply-to-group").withPriority((short) 6).withGroupId("group").withContentType("text/plain").withCorrelationId("correlation-" + m.getPayload()).withUserId("user").withDeliveryAnnotations("some-delivery-annotation", "da-value").withMessageAnnotations("some-msg-annotation", "ma-value").withApplicationProperties(new JsonObject().put("key", "value")).withFooter("my-trailer", "hello-footer").build())).subscribe((Subscriber<? super Message<Integer>>) sink.build());
assertThat(msgsReceived.await(6, TimeUnit.SECONDS)).isTrue();
AtomicInteger count = new AtomicInteger();
messagesReceived.forEach(msg -> {
assertThat(msg.getAddress()).isEqualTo(address);
assertThat(msg.getSubject()).isEqualTo("subject");
assertThat(msg.getMessageId()).isEqualTo("my-id");
assertThat(msg.getReplyTo()).isEqualTo("reply-to");
assertThat(msg.getReplyToGroupId()).isEqualTo("reply-to-group");
assertThat(msg.getPriority()).isEqualTo((short) 6);
assertThat(msg.getTtl()).isEqualTo(3000);
assertThat(msg.getGroupId()).isEqualTo("group");
assertThat(msg.getContentType()).isEqualTo("text/plain");
assertThat(msg.getCorrelationId()).isEqualTo("correlation-" + count.get());
assertThat(msg.isFirstAcquirer()).isFalse();
assertThat(msg.getUserId()).isEqualTo("user".getBytes(StandardCharsets.UTF_8));
assertThat(msg.getDeliveryAnnotations()).isNotNull();
assertThat(msg.getDeliveryAnnotations().getValue()).containsExactly(entry(Symbol.valueOf("some-delivery-annotation"), "da-value"));
assertThat(msg.getMessageAnnotations()).isNotNull();
assertThat(msg.getMessageAnnotations().getValue()).containsExactly(entry(Symbol.valueOf("some-msg-annotation"), "ma-value"));
assertThat(msg.getApplicationProperties()).isNotNull();
assertThat(msg.getApplicationProperties().getValue()).containsExactly(entry("key", "value"));
assertThat(msg.getFooter()).isNotNull();
// noinspection unchecked
assertThat(msg.getFooter().getValue()).containsExactly(entry("my-trailer", "hello-footer"));
Section body = msg.getBody();
assertThat(body).isInstanceOf(AmqpValue.class);
assertThat(((AmqpValue) body).getValue()).isEqualTo(count.get());
count.incrementAndGet();
});
assertThat(count.get()).isEqualTo(msgCount);
}
use of org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder in project smallrye-reactive-messaging by smallrye.
the class EventBusSinkTest method testSinkUsingInteger.
@SuppressWarnings("unchecked")
@Test
public void testSinkUsingInteger() {
String topic = UUID.randomUUID().toString();
AtomicInteger expected = new AtomicInteger(0);
usage.consumeIntegers(topic, 10, 10, TimeUnit.SECONDS, v -> expected.getAndIncrement());
Map<String, Object> config = new HashMap<>();
config.put("address", topic);
EventBusSink sink = new EventBusSink(vertx, new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));
SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
Multi.createFrom().range(0, 10).map(v -> (Message<?>) Message.of(v)).subscribe((Subscriber<Message<?>>) subscriber.build());
await().untilAtomic(expected, is(10));
assertThat(expected).hasValue(10);
}
Aggregations