You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求指导:用WSO2集成流实现ActiveMQ队列消费并生成CAR包部署

用WSO2 EI 7.1.0中介器流实现ActiveMQ SumResult队列消费(可生成CAR包部署)

前置准备

  • 确保WSO2 Integration Studio 8.0已配置EI 7.1.0运行环境
  • 下载ActiveMQ的activemq-client-x.x.x.jar和geronimo-jms_2.0_spec-x.x.x.jar,放到EI的<EI_HOME>/lib目录,同时在Integration Studio的项目依赖中添加这两个包

步骤1:创建集成项目与代理服务

  1. 打开WSO2 Integration Studio,新建Integration Project,命名为ActiveMQ-SumResult-Consumer
  2. 在项目内新建Proxy Service,选择Custom Proxy,命名为SumResultQueueConsumerProxy

步骤2:配置JMS端点(连接ActiveMQ)

  1. 在代理服务的设计视图,点击Add Endpoint,选择JMS Endpoint
  2. 填写核心配置参数:
    • Connection Factory: 输入QueueConnectionFactory(对应ActiveMQ默认队列连接工厂)
    • Destination: 输入SumResult(目标队列名称)
    • JMS Provider URL: 输入tcp://<ActiveMQ_IP>:61616(替换为你的ActiveMQ地址与端口)
    • Username/Password: 填写ActiveMQ认证信息(若开启了认证)
  3. 保存端点,命名为SumResultQueueEndpoint

步骤3:构建中介器消费流

  1. 回到代理服务设计视图,将上述端点设置为Inbound Endpoint(队列消费属于入站流)
  2. 添加中介器处理消息:
    • 若需打印接收结果,添加Log Mediator,日志级别设为INFO,日志内容填Received sum result: $body
    • 若需后续业务处理(如存储到数据库、转发至其他服务),可添加Call Mediator或DB Mediator等
  3. 示例完整流配置(XML):
    <?xml version="1.0" encoding="UTF-8"?>
    <proxy name="SumResultQueueConsumerProxy" startOnLoad="true" transports="jms" xmlns="http://ws.apache.org/ns/synapse">
        <target>
            <inSequence>
                <log level="custom">
                    <property name="STATUS" value="Successfully received sum result from ActiveMQ"/>
                    <property name="SUM_RESULT" expression="$body"/>
                </log>
                <!-- 此处可添加后续业务逻辑,比如转发至其他服务 -->
                <respond/>
            </inSequence>
            <outSequence/>
            <faultSequence>
                <log level="custom">
                    <property name="ERROR" value="Failed to process sum result message"/>
                    <property name="ERROR_DETAILS" expression="$ctx:ERROR_MESSAGE"/>
                </log>
            </faultSequence>
        </target>
        <parameter name="transport.jms.ContentType">
            <rules>
                <jmsProperty>contentType</jmsProperty>
                <default>text/plain</default>
            </rules>
        </parameter>
        <parameter name="transport.jms.ConnectionFactory">QueueConnectionFactory</parameter>
        <parameter name="transport.jms.Destination">SumResult</parameter>
    </proxy>
    

步骤4:配置EI的JMS连接

  1. 打开EI的<EI_HOME>/conf/deployment.toml,添加ActiveMQ连接配置:
    [[transport.jms.listener]]
    name = "QueueConnectionFactory"
    parameter.initial_naming_factory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
    parameter.provider_url = "tcp://<ActiveMQ_IP>:61616"
    parameter.connection_factory_name = "QueueConnectionFactory"
    parameter.connection_factory_type = "queue"
    # 若ActiveMQ开启认证,取消下方注释并填写信息
    # parameter.username = "admin"
    # parameter.password = "admin"
    

步骤5:生成CAR包并部署

  1. 在Integration Studio中,右键点击集成项目,选择New -> Composite Application Project
  2. 命名为ActiveMQ-SumResult-Consumer-CAR,将之前创建的代理服务与端点添加到该复合应用中
  3. 右键点击复合应用项目,选择Export Composite Application Project,生成CAR包
  4. 将CAR包放入EI的<EI_HOME>/repository/deployment/server/carbonapps目录,EI会自动完成部署

功能验证

  1. 启动ActiveMQ与EI服务
  2. 用你的Spring TS Web服务发送求和结果到SumResult队列
  3. 查看EI日志(<EI_HOME>/repository/logs/wso2carbon.log),可看到打印的求和结果信息

内容的提问来源于stack exchange,提问作者Jesus Red

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 06:00:18