Skip to content

Getting Started

The easiest way to start using SmallRye Reactive Messaging is from Quarkus. SmallRye Reactive Messaging can also be used standalone, or with Open Liberty.

First, go to code.quarkus.io. Select the smallrye-reactive-messaging extension (already done if you use the link), and then click on the generate button to download the code.

One downloaded, unzip the project and import it in your IDE.

If you look at the pom.xml file, you will see the following dependency:

1
2
3
4
 <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-smallrye-reactive-messaging</artifactId>
</dependency>

It provides the support for SmallRye Reactive Messaging.

Ok, so far so good, but we need event-driven beans.

Create the quickstart package, and copy the following class into it:

For instance:

package quickstart;

import jakarta.enterprise.context.ApplicationScoped;

import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.eclipse.microprofile.reactive.messaging.Outgoing;

import io.smallrye.mutiny.Multi;

@ApplicationScoped
public class ReactiveMessagingExample {

    @Outgoing("source")
    public Multi<String> source() {
        return Multi.createFrom().items("hello", "from", "SmallRye", "reactive", "messaging");
    }

    @Incoming("source")
    @Outgoing("processed-a")
    public String toUpperCase(String payload) {
        return payload.toUpperCase();
    }

    @Incoming("processed-a")
    @Outgoing("processed-b")
    public Multi<String> filter(Multi<String> input) {
        return input.select().where(item -> item.length() > 4);
    }

    @Incoming("processed-b")
    public void sink(String word) {
        System.out.println(">> " + word);
    }

}

This class contains a set of methods:

  • producing messages (source)
  • processing messages (toUpperCase)
  • transforming the stream by skipping messages (filter)
  • consuming messages (sink)

Each of these methods are connected through channels.

Now, let's see this in action. For the terminal, run:

> ./mvnw quarkus:dev

Running the previous example should give the following output:

1
2
3
4
>> HELLO
>> SMALLRYE
>> REACTIVE
>> MESSAGE

Of course, this is a very simple example. To go further, let's have a look to the core concepts behind SmallRye Reactive Messaging.