WSO2 ESB 5.0.0 配置消息存储

  • 一、配置数据源
    • 1、添加数据源
    • 2、添加存储数据的表
  • 二、配置接口
    • 1、添加 Message Store
    • 2、在 API 中添加 Store
    • 3、发布应用
    • 4、Postman 测试
  • 三、查看存储的消息
    • 1、查看消息内容
      • Main.java
      • Utils.java
    • 2、查看消息

一、配置数据源

1、添加数据源

配置 --> 数据源 --> 添加数据源

2、添加存储数据的表

CREATE TABLE jdbc_message_store(indexId BIGINT( 20 ) NOT NULL AUTO_INCREMENT ,msg_id VARCHAR( 200 ) NOT NULL ,message BLOB NOT NULL ,PRIMARY KEY ( indexId )
);

二、配置接口

1、添加 Message Store



MsgStore.xml

<?xml version="1.0" encoding="UTF-8"?>
<messageStore class="org.apache.synapse.message.store.impl.jdbc.JDBCMessageStore" name="MsgStore" xmlns="http://ws.apache.org/ns/synapse"><parameter name="store.jdbc.dsName">MySQL</parameter><parameter name="store.producer.guaranteed.delivery.enable">false</parameter><parameter name="store.jdbc.table">jdbc_message_store</parameter>
</messageStore>

2、在 API 中添加 Store

3、发布应用

4、Postman 测试

未接到消息时为0.

postman发送报文

再次刷新消息存储,消息变为1了!

数据库表也存储了这条消息

三、查看存储的消息

1、查看消息内容

不能直接查看 message 内容,需要另外使用程序查看,因为 blob 存储的是对象。查看源码它是使用 ObjectInputStream 读取消息的。

使用 Eclipse Java 新建一个工程

导入 WSO2 包:WSO2ESB_HOME\repository\components\plugins\synapse-core_2.1.7.wso2v7.jar
JDBC包:mysql-connector-java-5.1.26.jar
fastjson包:fastjson-1.2.15.jar

Main.java

package com;import java.util.List;
import java.util.Map;import org.apache.synapse.message.store.impl.commons.StorableMessage;import com.alibaba.fastjson.JSON;public class Main {public static void main(String[] args) {// TODO 自动生成的方法存根String[] field = { "indexId", "msg_id", "message" };String sqlString = "SELECT indexId,msg_id,message FROM jdbc_message_store;";List<Object> msgList = Utils.getMysqlInfo(sqlString, field);String indexId = "", msg_id = "";StorableMessage message = null;// 行数for (int i = 0; i < (msgList.size() / field.length); i++) {// 列数for (int j = 0; j < field.length; j++) {if (j == 0) {indexId = (String) msgList.get(i * field.length + j);}if (j == 1) {msg_id = (String) msgList.get(i * field.length + j);}if (j == 2) {message = (StorableMessage)msgList.get(i * field.length + j);}}//System.out.println(indexId + "\t" + msg_id);Map map = message.getAxis2message().getProperties();System.out.println(JSON.toJSON(map));Map map2 = message.getSynapseMessage().getProperties();System.out.println(JSON.toJSON(map2));}}}

Utils.java

package com;import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import org.apache.synapse.message.store.impl.commons.StorableMessage;public class Utils {private static Connection conn;/*** 数据库连接* * @return*/public static Connection getsourcedata() {String dburl = "";String username = "";String password = "";dburl = "jdbc:mysql://localhost:3306/Carbon_WSO2?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=GMT%2B8";username = "wxhntmy";password = "123456";try {Class.forName("com.mysql.jdbc.Driver");conn = DriverManager.getConnection(dburl, username, password);System.out.println("数据库连接成功!");} catch (Exception e) {e.printStackTrace();}return conn;}/*** 查询数据库获取结果* * @param sql   "SQL语句"* @param field "字段" 可传多值,String[]* @return*/public static List<Object> getMysqlInfo(String sql, String... field) {List<Object> respon = new ArrayList<>();PreparedStatement pstmt = null;Connection con = Utils.getsourcedata();
//      getLogger("supplier_receive_java","getMysqlInfo_<field>",field);try {pstmt = con.prepareStatement(sql);ResultSet result = pstmt.executeQuery();System.out.println("utils 最终运行SQL: " + pstmt);while (result.next()) {for (String string : field) {if ("message".equals(string)) {byte[] msgObj = result.getBytes(string);if (msgObj != null) {ObjectInputStream ios = null;try {ios = new ObjectInputStream(new ByteArrayInputStream(msgObj));Object msg = ios.readObject();if (msg instanceof StorableMessage) {StorableMessage jdbcMsg = (StorableMessage)msg;//System.out.println(jdbcMsg);respon.add(jdbcMsg);}} catch (Exception e) {e.printStackTrace();} finally {try {ios.close();} catch (IOException e) {e.printStackTrace();}}continue;}} else {respon.add(result.getString(string));}}}pstmt.close();con.close();} catch (SQLException e) {e.printStackTrace();try {con.close();} catch (SQLException e1) {e1.printStackTrace();}}return respon;}}

2、查看消息


message.getAxis2message().getProperties()

message.getSynapseMessage().getProperties(),这里可以看到我们设置的属性

WSO2 ESB 5.0.0 配置消息存储相关推荐

  1. Microsoft BizTalk ESB Toolkit 2.0

    [>>> 更多<BizTalk开发系列>文章 ] 微软于6月8号发布了BizTalk Server 2009企业集成平台的最后一个功能组件:ESB Toolkit 2.0 ...

  2. RocketMQ5.0.0消息存储<四>_刷盘机制

    目录 一.刷盘概览 二.Broker刷盘机制 1. 同步刷盘 2. 异步刷盘 1):未开启堆外内存池 2):开启堆外内存池 三.参考资料 一.刷盘概览 RocketMQ存储与读写是基于JDK NIO的 ...

  3. 在Win 8.1上安装配置FlashDevelop5.0.0

    FlashDevelop是基于.NET框架的开源软件,只能在Windows环境下面运行,相较于Flash CS和FlexBuilder, 它非常轻量级.FlashDevelop只是一个代码编辑器,而不 ...

  4. CentOS7安装配置redis-3.0.0

    一.安装必要包 yum install gcc 二.linux下安装 #下载 wget http://download.redis.io/releases/redis-3.0.0.tar.gz tar ...

  5. centos下tomcat6.0.28配置

    系统环境:centos 6.3 64bit  IP:192.168.1.108 tomcat版本:apache-tomcat-6.0.28.tar.gz jdk版本: jdk-6u18-linux-x ...

  6. creo 3.0计算机配置,Creo 3.0 Parametric 配置选项文件使用说明

    最近安装了Creo Parametric 3.0 F000,其配置选项与Creo Parametric 2.0有部分更新,研究PTC Creo® 3.0 Parametric 配置选项configop ...

  7. Apache简单配置(4)搭建Discuz 7.0.0论坛

    Apache简单配置(4)搭建Discuz 7.0.0论坛 RHEL5.3 基本网络配置 一. 1.RHEL5 U3:如图1 (如图1) 2.#hostname //查看当前主机的主机名:如图2 (如 ...

  8. CentOS 7.0系统安装配置图解教程

    一.安装CentOS 7.0 成功引导系统后,会出现下面的界面 frameborder="0" scrolling="no" vspace="0&qu ...

  9. grafana3.1.0安装配置

    Grafana 是 Graphite 和 InfluxDB 仪表盘和图形编辑器.Grafana 是开源的,功能齐全的度量仪表盘和图形编辑器,支持 Graphite,InfluxDB 和 OpenTSD ...

  10. Boost1.62.0 + VS2015 配置

    Boost1.62.0 + VS2015 配置 标签: 

最新文章

  1. Windows Mobile 与 PC之间的通过蓝牙(Bluetooth) 传输文件的开发
  2. oozie案例——自定义MapReduce workflow
  3. Object.defineProperty()方法的用法详解
  4. 组合模式(Composite)
  5. python 错误处理 assert
  6. 【drp 11】使用Junit简单测试接口方法
  7. javascript php 传值,js 传值到 PHP 有关问题
  8. ladder怎么读_ladder 是什么意思_ladder 的翻译_音标_读音_用法_例句_爱词霸在线词典...
  9. 学习Dubbo 影院模块 所得所获?
  10. 【机器学习】监督学习--(分类)支持向量机SVM①
  11. python之父的名字-Python 常见双下划线关键字的用法
  12. Direct3D顶点结构使用总结
  13. Who Is Answering My Quries:Understanding and Characterizing Interception of the DNS Resolution Path
  14. html+上下标+遇乘号无效,html中的特殊符号
  15. Linux:Linux文件属性
  16. 我已经租不起回龙观的房子了
  17. 【Albert带你1小时看遍美国前沿科技与商业运作】微访谈精选
  18. ubuntu使用清华源pip安装pytorch
  19. Hadoop2.x高可用架构
  20. ProMax v2.0.7047 1CD流程模拟软件

热门文章

  1. Chromium OS?本土化气息的的Flint OS
  2. 弹弹堂手游语音服务器怎么连接,腾讯弹弹堂手游空间怎么进去 互动玩法攻略介绍...
  3. 【资料总结】html开发小实例
  4. 威金病毒完全解决方案篇
  5. 蓝桥杯 等差素数列(python实现)
  6. 【附源码】计算机毕业设计SSM汽车租赁管理系统
  7. python百度地图api添加坐标点_python调用百度地图API实现经纬度换算、热力地图全流程指南...
  8. Android上的APP图标常见尺寸规范
  9. windows微信协议|PC微信协议829版
  10. 物联网和区块链:挑战与风险