MicroProfile reactive messaging examples

In this section, we will cover some examples of using MP-RM to create CDI beans that produce and consume messages.

Let's say you want a CDI bean to act as a source of a Message<String> such that whenever its publishMessage(String) method is called, an MP-RM message is posted to some MP-RM channel. To do this, we need to define a connector that bridges between the CDI bean and the MP-RM layer. An example of an incoming message connector that does this is shown in the following code:

package io.pckt.reactive;import javax.enterprise.context.ApplicationScoped;import javax.inject.Inject;import org.eclipse.microprofile.config.Config;import org.eclipse.microprofile.reactive.messaging.Message;import org.eclipse.microprofile.reactive.messaging.spi. ...

Get Hands-On Enterprise Java Microservices with Eclipse MicroProfile now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.