use of org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testBroadcastWithPartitions.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBroadcastWithPartitions() {
companion.topics().create(topic, 2);
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("broadcast", true).with("partitions", 2);
connector = new KafkaConnector();
connector.executionHolder = new ExecutionHolder(vertx);
connector.configurations = UnsatisfiedInstance.instance();
connector.consumerRebalanceListeners = UnsatisfiedInstance.instance();
connector.kafkaCDIEvents = new CountKafkaCdiEvents();
connector.init();
PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector.getPublisherBuilder(config);
List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
assertThat(messages1.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactlyInAnyOrder(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(messages2.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactlyInAnyOrder(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
use of org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder in project smallrye-reactive-messaging by smallrye.
the class KafkaSourceWithLegacyMetadataTest method testBroadcast.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testBroadcast() {
MapBasedConfig config = newCommonConfigForSource().with("value.deserializer", IntegerDeserializer.class.getName()).with("broadcast", true);
CountKafkaCdiEvents testEvents = new CountKafkaCdiEvents();
connector = new KafkaConnector();
connector.executionHolder = new ExecutionHolder(vertx);
connector.configurations = UnsatisfiedInstance.instance();
connector.consumerRebalanceListeners = UnsatisfiedInstance.instance();
connector.kafkaCDIEvents = testEvents;
connector.init();
PublisherBuilder<? extends KafkaRecord> builder = (PublisherBuilder<? extends KafkaRecord>) connector.getPublisherBuilder(config);
List<KafkaRecord> messages1 = new ArrayList<>();
List<KafkaRecord> messages2 = new ArrayList<>();
builder.forEach(messages1::add).run();
builder.forEach(messages2::add).run();
companion.produceIntegers().usingGenerator(i -> new ProducerRecord<>(topic, i), 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
assertThat(messages1.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(messages2.stream().map(KafkaRecord::getPayload).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(testEvents.firedConsumerEvents.sum()).isEqualTo(1);
assertThat(testEvents.firedProducerEvents.sum()).isEqualTo(0);
}
use of org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder in project smallrye-reactive-messaging by smallrye.
the class AmqpConnector method getPublisherBuilder.
@Override
public PublisherBuilder<? extends Message<?>> getPublisherBuilder(Config config) {
AmqpConnectorIncomingConfiguration ic = new AmqpConnectorIncomingConfiguration(config);
String address = ic.getAddress().orElseGet(ic::getChannel);
opened.put(ic.getChannel(), false);
boolean broadcast = ic.getBroadcast();
boolean durable = ic.getDurable();
boolean autoAck = ic.getAutoAcknowledgement();
AmqpClient client = AmqpClientHelper.createClient(this, ic, clientOptions);
String link = ic.getLinkName().orElseGet(ic::getChannel);
ConnectionHolder holder = new ConnectionHolder(client, ic, getVertx());
holders.put(ic.getChannel(), holder);
AmqpFailureHandler onNack = createFailureHandler(ic);
Multi<? extends Message<?>> multi = holder.getOrEstablishConnection().onItem().transformToUni(connection -> connection.createReceiver(address, new AmqpReceiverOptions().setAutoAcknowledgement(autoAck).setDurable(durable).setLinkName(link).setCapabilities(getClientCapabilities(ic)))).onItem().invoke(r -> opened.put(ic.getChannel(), true)).onItem().transformToMulti(r -> getStreamOfMessages(r, holder, address, ic.getChannel(), onNack, ic.getCloudEvents(), ic.getTracingEnabled()));
Integer interval = ic.getReconnectInterval();
Integer attempts = ic.getReconnectAttempts();
multi = multi.onFailure().invoke(log::retrieveMessagesRetrying).onFailure().retry().withBackOff(ofSeconds(1), ofSeconds(interval)).atMost(attempts).onFailure().invoke(t -> {
opened.put(ic.getChannel(), false);
log.retrieveMessagesNoMoreRetrying(t);
});
if (broadcast) {
multi = multi.broadcast().toAllSubscribers();
}
return ReactiveStreams.fromPublisher(multi);
}
use of org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder in project smallrye-reactive-messaging by smallrye.
the class MqttSourceTest method testBroadcast.
@Test
public void testBroadcast() {
String topic = UUID.randomUUID().toString();
Map<String, Object> config = new HashMap<>();
config.put("topic", topic);
config.put("host", address);
config.put("port", port);
config.put("channel-name", topic);
config.put("broadcast", true);
MqttSource source = new MqttSource(vertx, new MqttConnectorIncomingConfiguration(new MapBasedConfig(config)));
List<MqttMessage<?>> messages1 = new ArrayList<>();
List<MqttMessage<?>> messages2 = new ArrayList<>();
PublisherBuilder<MqttMessage<?>> stream = source.getSource();
stream.forEach(messages1::add).run();
stream.forEach(messages2::add).run();
await().until(source::isReady);
AtomicInteger counter = new AtomicInteger();
new Thread(() -> usage.produceIntegers(topic, 10, null, counter::getAndIncrement)).start();
await().atMost(2, TimeUnit.MINUTES).until(() -> messages1.size() >= 10);
await().atMost(2, TimeUnit.MINUTES).until(() -> messages2.size() >= 10);
assertThat(messages1.stream().map(Message::getPayload).map(x -> (byte[]) x).map(bytes -> Integer.valueOf(new String(bytes))).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
assertThat(messages2.stream().map(Message::getPayload).map(x -> (byte[]) x).map(bytes -> Integer.valueOf(new String(bytes))).collect(Collectors.toList())).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}
use of org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder in project smallrye-reactive-messaging by smallrye.
the class MqttServerConnectorTest method test.
@Test
void test(@Any MqttServerConnector connector, VertxTestContext testContext) {
final AtomicBoolean opened = new AtomicBoolean();
final Map<String, String> configMap = new HashMap<>();
configMap.put("port", "0");
final List<TestMqttMessage> testMessages = new CopyOnWriteArrayList<>();
testMessages.add(new TestMqttMessage("hello/topic", 1, "Hello world!", EXACTLY_ONCE.value(), false));
testMessages.add(new TestMqttMessage("foo/bar", 2, "dkufhdspkjfosdjfs;", AT_LEAST_ONCE.value(), true));
testMessages.add(new TestMqttMessage("foo/bar", -1, "Hello world!", AT_MOST_ONCE.value(), false));
testMessages.add(new TestMqttMessage("sa/srt/tgvbc", 3, "Yeah", EXACTLY_ONCE.value(), true));
final PublisherBuilder<MqttMessage> builder = (PublisherBuilder<MqttMessage>) connector.getPublisherBuilder(TestUtils.config(configMap));
// The source is the same for every call
assertEquals(builder, connector.getPublisherBuilder(TestUtils.config(configMap)));
builder.buildRs().subscribe(createSubscriber(testContext, opened, testMessages));
TestUtils.sendMqttMessages(testMessages, CompletableFuture.supplyAsync(() -> {
await().until(opened::get);
await().until(() -> connector.port() != 0);
return connector.port();
}), testContext);
}
Aggregations