import org.apache.kafka.common.errors.WakeupException;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
+import reactor.core.publisher.Sinks;
import java.net.URI;
import java.time.*;
{
EventShardAssigned to = EventShardAssigned.of(shard, instanceUri);
- return Mono.create(sink ->
- {
- ProducerRecord<String, AbstractMessageTo> record =
- new ProducerRecord<>(
- topic,
- Integer.toString(shard),
- to);
+ Sinks.One sink = Sinks.unsafe().one();
- producer.send(record, ((metadata, exception) ->
+ ProducerRecord<String, AbstractMessageTo> record =
+ new ProducerRecord<>(
+ topic,
+ Integer.toString(shard),
+ to);
+
+ producer.send(record, ((metadata, exception) ->
+ {
+ if (metadata != null)
{
- if (metadata != null)
- {
- log.info("Successfully sent shard assigned event for shard: {}", shard);
- sink.success(metadata);
- }
- else
- {
- // On send-failure
- log.error(
- "Could not send shard assigned event for shard {}: {}",
- shard,
- exception);
- sink.error(exception);
- }
- }));
- });
+ log.info("Successfully sent shard assigned event for shard: {}", shard);
+ sink.emitValue(metadata, Sinks.EmitFailureHandler.FAIL_FAST);
+ }
+ else
+ {
+ // On send-failure
+ log.error(
+ "Could not send shard assigned event for shard {}: {}",
+ shard,
+ exception);
+ sink.emitError(exception, Sinks.EmitFailureHandler.FAIL_FAST);
+ }
+ }));
+
+ return sink.asMono();
}
Mono<RecordMetadata> sendShardRevokedEvent(int shard)
{
EventShardRevoked to = EventShardRevoked.of(shard, instanceUri);
- return Mono.create(sink ->
- {
- ProducerRecord<String, AbstractMessageTo> record =
- new ProducerRecord<>(
- topic,
- Integer.toString(shard),
- to);
+ Sinks.One sink = Sinks.unsafe().one();
- producer.send(record, ((metadata, exception) ->
+ ProducerRecord<String, AbstractMessageTo> record =
+ new ProducerRecord<>(
+ topic,
+ Integer.toString(shard),
+ to);
+
+ producer.send(record, ((metadata, exception) ->
+ {
+ if (metadata != null)
{
- if (metadata != null)
- {
- log.info("Successfully sent shard revoked event for shard: {}", shard);
- sink.success(metadata);
- }
- else
- {
- // On send-failure
- log.error(
- "Could not send shard revoked event for shard {}: {}",
- shard,
- exception);
- sink.error(exception);
- }
- }));
- });
+ log.info("Successfully sent shard revoked event for shard: {}", shard);
+ sink.emitValue(metadata, Sinks.EmitFailureHandler.FAIL_FAST);
+ }
+ else
+ {
+ // On send-failure
+ log.error(
+ "Could not send shard revoked event for shard {}: {}",
+ shard,
+ exception);
+ sink.emitError(exception, Sinks.EmitFailureHandler.FAIL_FAST);
+ }
+ }));
+
+ return sink.asMono();
}