0

I'm new to reactive programming and I try to implement a very basic scenario. I want to send a message to kafka each time a file is dropped to a specific folder. I think that I don't understand well the basics things... so please could you help me?

So I have a few questions : What is the difference between smallrye-reactive-messaging and smallrye-reactive-streams-operators ?

I have this simple code :

@Outgoing( "my-topic" )
public PublisherBuilder<Message<MessageWrapper>> generate() {
     if(Objects.isNull(currentMessage)){
          //currentMessage is an instance variable which is null when I start the application
          return ReactiveStreams.of(new MessageWrapper()).map(Message::of);
     }
     else {
          //currentMessage has been correctly set with the file information
          LOGGER.info(currentMessage);
          return ReactiveStreams.of(currentMessage).map(Message::of);
     }
}

When the code goes in the if statement, everything is ok and I got a JSON serialization of my object will null values. However I don't understand why when my code goes to the else statement, nothing goes to the topic? It seems that the .of instructions of the if statement has broke the streams or something like that...

How to keep a continuous streams that 'react' to the new dropped files ? (or other events like HTTP GET request or something like that) ...

If I don't return an instance of PublisherBuilder but an Integer for example, then my kafka topic will be populated by a very huge stream of Integer value. This is why examples are using some intervals when sending messages...

Should I use some CompletationStage or CompletableFuture ? RxJAva2? It's a bit confusing which lib to use (vertx, smallrye, rxjava2, microprofile, ...)

What are the differences between :

  • ReactiveStreams.fromCompletionStage
  • ReactiveStreams.fromProcessor
  • ReactiveStreams.fromPublisher
  • ReactiveStreams.fromSubscriber

Which one to use on which scenario ?

Thank you very much !

bdeweer
  • 135
  • 1
  • 14

1 Answers1

0

Let's start with the difference between smallrye-reactive-messaging & smallrye-reactive-streams-operators: smallrye-reactive-streams-operators is the same as smallrye-reactive-messaging but in addition it has a support to MicroProfile-context-propagation. Since most reactive-messaging providers use Vert.x behind the scene, it will process your message in an event-loop style, which means it will run in separate thread. Sometimes you need to propagate some ctx from your base thread into the new thread (ex: populating CDI and Tx context to execute some JPA Entity manager logic). Here where ctx propagation help.

For method signatures. You can take a look at the official documentation of SmallRye-reactive-streams sections 3,4 & 5. Each one has a different use case. It is up to you which flavor do you want to use.

When to use what ? If you are not running within reactive context, you can use the below to send messages.

@Inject @Channel("my-channel") Emitter emitter;

For Message consumption you can use method signature like this :

@Incoming("channel-2") public CompletionStage doSomething(Message anEvent)

Or

@Incoming("channel-2") public void doSomething(String anEvent)

Hope that helps.

iabughosh
  • 481
  • 5
  • 19