O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required