liveBook · Manning

SmallRye Reactive Messaging

As explained in Quarkus in Action

SmallRye Reactive Messaging is an implementation of reactive messaging APIs for connecting application channels with message brokers and other messaging providers.

SmallRye Reactive Messaging implements MicroProfile Reactive Messaging in Quarkus. It controls asynchronous message flow through application channels and adds features beyond the specification, including broadcast and connectors for external messaging systems. Messaging integrations can also use blocking APIs. section 9.10 section 9.3.2

A CDI bean produces messages with @Outgoing, consumes them with @Incoming, or processes them with both. A channel ordinarily has one producer and one consumer; processors use distinct channel names to establish their order. SmallRye can additionally broadcast messages from one channel to multiple consumers. Reactive methods can use Mutiny’s Multi, a Publisher subtype. section 9.3.2

From an in-memory flow to a broker

An @Outgoing("ticks") method emits five ticks one second apart. A processor turns them into timestamps on the times channel, where an @Incoming consumer prints them. To connect services through a broker, add a connector extension: smallrye-kafka for Kafka or quarkus-messaging-rabbitmq for RabbitMQ. The same channel-based API applies to in-memory and remote messaging, so moving an existing flow to RabbitMQ requires limited application changes. section 9.3.2 section 9.6 section 9.7

For RabbitMQ, an invoices producer can inject @Channel("invoices") MutinyEmitter<Invoice>, while a Billing service consumes from @Incoming("invoices-rabbitmq"). Configuration maps the incoming channel to the invoices exchange and queue. Connector extensions provide Dev Services that start brokers and connect applications in Dev mode; those development conveniences do not replace deliberate broker configuration outside Dev mode. section 9.7 section 9.10

Listing 9.1 MicroProfile Reactive Messaging with Mutiny example
@Outgoing("ticks")
public Multi<Long> aFewTicks() {
    return Multi.createFrom()
        .ticks().every(Duration.ofSeconds(1))
        .select().first(5);
}

@Incoming("ticks")
@Outgoing("times")
public Multi<String> processor(Multi<Long> ticks) {
    return ticks.map(tick -> Instant.now().toString());
}

@Incoming("times")
public void consumer(String payload) {
    System.out.println(payload);
}

The complete ticks-to-times listing shows a Mutiny producer, processor, and consumer connected by annotated channels. section 9.3.2

How Quarkus in Action covers it

How deep it goes
Works through annotated methods and broker integration, but defers Kafka internals.
Examples
Uses a five-tick timestamp pipeline and invoice messages exchanged between services through RabbitMQ.
What it assumes
Builds on CDI bean methods and previously introduced Mutiny while explaining messaging roles and connectors.
What you can do after
Apply it via Quarkus messaging extensions to connect annotated channels to Kafka or RabbitMQ.
How it connects
Links MicroProfile Reactive Messaging, CDI, Mutiny, connectors, Dev Services, Kafka, and RabbitMQ.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.