Enterprise 上級

メッセージ駆動BeanとReactive Messagingの比較

JMSメッセージ駆動BeanをMicroProfile Reactive Messagingによるシンプルなイベント処理に置き換える。

✕ Java EE
@MessageDriven(activationConfig = {
    @ActivationConfigProperty(
        propertyName = "destinationType",
        propertyValue = "jakarta.jms.Queue"),
    @ActivationConfigProperty(
        propertyName = "destination",
        propertyValue = "java:/jms/OrderQueue")
})
public class OrderMDB implements MessageListener {
    @Override
    public void onMessage(Message message) {
        TextMessage txt = (TextMessage) message;
        processOrder(txt.getText());
    }
}
✓ MicroProfile 4+
@ApplicationScoped
public class OrderProcessor {
    @Incoming("orders")
    public void process(Order order) {
        // automatically deserialized from
        // the "orders" channel
        fulfillOrder(order);
    }
}
このコードに問題がありますか? お知らせください。
🪶

最小限のコード

単一の@Incomingメソッドが、MDBクラス・MessageListenerインターフェース・アクティベーション設定を置き換えます。

🔌

ブローカー非依存

Kafka・AMQP・JMSコネクターを設定変更だけで切り替えられ、アプリケーションコードを変更する必要がありません。

☁️

クラウドネイティブ対応

リアクティブストリームのバックプレッシャーと軽量ランタイムにより、コンテナ化デプロイに最適です。

旧来のアプローチ
メッセージ駆動Bean
モダンなアプローチ
Reactive Messaging
JDKバージョン
11
難易度
上級
メッセージ駆動BeanとReactive Messagingの比較
利用可能

MicroProfile 4.0 / SmallRye Reactive Messaging以降、利用可能

メッセージ駆動BeanはMessageListenerの実装・アクティベーションプロパティの設定・JMSメッセージの手動デシリアライズが必要です。MicroProfile Reactive Messagingはメソッドに@Incomingアノテーションを付けるだけで、型付きオブジェクトを直接受け取れます。チャネル設定は外部化されており、コードはブローカー非依存でテストも容易です。

共有 𝕏 🦋 in