ESB定义了消息的收发和收发池,对于各种通讯方式定义了收发API,在收到信息后由eventBus来发布消息

ISender:

 public abstract interface ISender
 {
     public abstract void send(Object paramObject) throws Exception;

     public abstract Object sendRequest(Object paramObject, double paramDouble) throws Exception;
 }

IListener:

 public abstract interface IListener
 {
     public abstract void connect()
         throws Exception;
     public abstract void disconnect()
         throws Exception;
     public abstract boolean isconnect()
         throws Exception;
     public abstract void destroy()
         throws Exception;
 }

SenderPool: 可以用GenericKeyedObjectPool<String, ISender>代替(线程安全的)

 public abstract class SenderPool extends BasePooledObjectFactory<ISender>
 {
     private String id;
     private ObjectPool<ISender> pool;
     id,pool getter, setter...
     public PooledObject<ISender> wrap(ISender sender) {
         return new DefaultPooledObject<ISender>(sender);
     }

     public ISender borrowClient() throws Exception {
         return (ISender)getPool().borrowObject();
     }

     public void returnClient(ISender sender) throws Exception {
         getPool().returnObject(sender);
     }

     public void destroy() throws Exception {
         getPool().clear();
     }
 }

ListenerPool: 可以用GenericKeyedObjectPool<String, IListener>代替pool, method: listAllObjects() 可以用来遍历各个PooledObject,省去了ListenerCf

 public abstract class ListenerPool
 {
     private String id;
     private ListenerCf config;
     private Set<IListener> pool = new CopyOnWriteArraySet<IListener>();
     private EventBus eventBus;

     constructor, getter, setter...

     public void connect() throws Exception() {
         for (IListener listener : getPool())
             listener.connect();
     }

     public void disconnect() throws Exception {
         for (IListener listener : getPool())
             listener.disconnect();
     }

     public boolean isconnect() throws Exception {
         for (IListener listener : getPool())
             if (!listener.isconnect()) return false;
         return true;
     }

     public void destroy() throws Exception {
         for (IListener listener : getPool())
             listener.destroy();
     }
 }

ESBFactory: map各个SenderPool, ListenerPool

 public abstract class ESBFactory
 {
     private Map<String, SenderPool> senderMap = new ConcurrentHashMap<String, SenderPool>();

     private Map<String, ListenerPool> listenerMap = new ConcurrentHashMap<String, ListenerPool>();

     public abstract void initialize();

     public void destroy() {对各个pool destroy并清空map}

     public void disconnect() {对各个pool disconnect}
 }

ESBComponent: @Startup, @Singleton

@Startup
@Singleton
public class ESBComponent {
    public static Set<ESBFactory> esbFactory = new CopyOnWriteArraySet();
    public static Map<String, SenderPool> senderMap = new ConcurrentHashMap();
    public static Map<String, ListenerPool> listenerMap = new ConcurrentHashMap();

    @PostConstruct
    public void initialize() {
        将esbFactory里的所有senderMap和ListenerMap中的所有Pool都整合到ESBComponent的senderMap和listenerMap中
    }

    @Lock(LockType.READ)
    public void disconnect() {
        。。。
    }

    @Lock(LockType.READ)
    public boolean disconnect(String listener) {
        ...
    }

    public boolean isConnected(String listener) {
        ...
    }

    @PreDestroy
    public void destroy() throws Exception {
        ...
    }

    static {
        esbFactory.add(new TibcoFactory());
        esbFactory.add(new FtpFactory());
        esbFactory.add(new FileFactory());
        esbFactory.add(new JmsFactory());
        esbFactory.add(new IbmMqFactory());
    }
}

=================================================================================================

JmsSender: 用javax.jms来实现ISender,send是用来向destination发送textMessage,sendRequest是发送完接受返回数据的。(可以将两个重载设计)

 public class JmsSender implements ISender {
     private String id;
     private Connection connection;
     private Session session;
     private int timeOut;
     private String destination;

     constructor with fields, setter, getter...

     public void send(String destination, Object object) throws Exception
     {
         InitialContext initialContext = null;
         try {
             initialContext = new InitialContext();
             Destination des = (Destination)initialContext.lookup(destination);
             MessageProducer producer = this.session.createProducer(des);
             Message message = null;
             if ((object instanceof String)) {
                 message = this.session.createTextMessage((String)object);
             }
             if (message != null) producer.send(message);
         }
         catch(JMSException e) {
             ...
         }
         finally {
             if (initialContext != null)
                 initialContext.close();
             }
         }
     }
     public Object sendRequest(String destination, Object object, double timeOut) throws Exception {
         InitialContext initialContext = null;
         try {
             initialContext = new InitialContext();
             Queue queue = (Queue) initialContext.lookup(destination);
             MessageProducer producer = this.session.createProducer(queue);
             TemporaryQueue replyQueue = this.session.createTemporaryQueue();
             MessageConsumer replyConsumer = this.seesion.createConsumer(replyQueue);
             Message message = null;
             if ((object instanceof String)) {
                 message = this.session.createTextMessage((String)object);
             }
             if (message != null) {
                 message.setJMSReplyTo(replyQueue);
                 producer.send(message);
                 Message replyMessage = replyConsumer.receive((long)timeOut);
                 return replyMessage;
             }
             replyConsumer.close();
             replyQueue.delete();
         }
         catch  (JMSException e) {
             ...
          }
         finally {
             if (initialContext != null) {
                 initialContext.close();
             }
         }
         return null;
     }

JmsSenderPool: extends SenderPool, 因此要实现create method.

 public class JmsSenderPool extends SenderPool
 {
     private JmsSenderCf config;

     constructor with fields, setter, getter...

     public ISender create() throw Exception
     {
         InitialContext initialContext = null;
         try {
             String destination = this.config.getDestination();
             initialContext = new initialContext();
             ConnectionFactory cfact = (ConnectionFactory)initialContext.lookup(this.config.getConnectionFactory());
             Connection connection = cfact.createConnection();
             Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
             connection.start();
             JmsSender sender = new JmsSender(getId(), connection, session, destination, this.config.getTimeOut());
             return sender;
         }
         finally {
             if (initialContext != null) initialContext.close();
         }
     }
 }

JmsListener: 实现IListener, MessageListener. (可以将IListener去掉,Consumer的创建放到JmsListenerPool中)

onMessage Method:

 public void onMessage(Message request)
 {
     try {
         JmsMessage message = new JmsMessage();
         message.setMessage(request);
         Destination replyQueue = request.getJMSReplyTo();
         if (replyQueue == null) {
             String replyTo = request.getStringProperty("JMSReplyTo");
             if ((replyTo != null) && (replyTo.trim().length() > 0)) {
                 replyQueue = (Destination) this.initialContext.lookup(replyTo);
             }
             if (replyQueue == null) replyQueue = this.defaultReplyQueue;
         }
         request.setJMSReplyTo(replyQueue);
         message.setConnection(this.connection);
         }
         this.eventBus.post(message);
     }
     catch ...
 }

最关键的是this.eventBus.post(message);即用eventBus发布消息

JmsListenerPool:

JmsFactory: 读取配置文件,并初始化ListenerPool和SenderPool

MES: ESB的更多相关文章

  1. 微服务理论之六:ESB与SOA的关系

    一.SOA和ESB一直是没有明确概念的两个缩略词 SOA----面向服务架构,实际上强调的是软件的一种架构,一种支撑软件运行的相对稳定的结构,表面含义如此,其实SOA是一种通过服务整合来解决系统集成的 ...

  2. 杂项:ESB接口

    ylbtech-杂项:ESB接口 ESB全称为Enterprise Service Bus,即企业服务总线.它是传统中间件技术与XML.Web服务等技术结合的产物.ESB提供了网络中最基本的连接中枢, ...

  3. 企业 SOA 设计(1)–ESB 设计

    最近为公司完成了一个 ESB 的设计.下面简要说明一下具体的设计方案.   企业 SOA 整体方案 在前一篇<SOA.ESB.NServiceBus.云计算 总结>中说到,SOA 是面向服 ...

  4. 面向服务架构(SOA)和企业服务总线(ESB)

    http://www.cnblogs.com/shanyou/archive/2008/04/19/1161452.html 学习和研究在企业中实施面向服务架构(SOA),简单回顾SOA和ESB,重点 ...

  5. 企业服务总线(ESB)

    思考: 1.ESB的定义到底是什么?是一款产品还是一种架构模式? 2.ESB有何实际用处? 定义ESB 对于企业服务总线(Enterprise Service Bus),目前还没有公认的定义,根据供应 ...

  6. 几种ESB(企业服务总线)介绍

    ESB(Enterprise Service Bus,即企业服务总线)是传统中间件技术与XML.Web服务等技术结合的产物.ESB提供了网络中最基本的连接中枢,是构筑企业神经系统的必要元素. 企业服务 ...

  7. ESB、SOA、EAI异同【转】

    先说概念:       ESB:企业服务总线(ESB : Enterprise Service Bus):ESB 是一种开放的.基于标准的分布式同步或异步信息传递中间件.通过 XML.Web Serv ...

  8. ESB 企业服务总线

    整理的OSChina 第 38 期高手问答 —— ESB 企业服务总线,嘉宾为@肖俊_David . @肖俊_David 恒拓开源架构师,热衷于JAVA开发,有多年的企业级开发经验.曾参和设计和开发基 ...

  9. REST、SOA、SOAP、RPC、ICE、ESB、BPM知识汇总及理解

    转载自处blog.csdn.net/tantexian. SOA: 维基百科解释:SOA:面向服务的软件架构(Service Oriented Architecture),是一种计算机软件的设计模式, ...

随机推荐

  1. MyBatis代码自动生成

    MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是由于手写映射文件很容易出错,所以可利用MyBatis生成器自动生成实 ...

  2. BLE-NRF51822教程17-DFU使用手机升级

    演示的工程是 [application]    nRF51_SDK_10.0.0_dc26b5e\examples\ble_peripheral\ble_app_hrs\pca10028\s110_w ...

  3. 智能手机,医疗诊断,云会议(gotomeeting/citrix)

    在诊断领域已出现很多大有希望的创新,它们可能会起到真正的变革作用. 例如,有一种新技术可以让健康护理工作者用一部智能手机拍摄高质量的视网膜图像.这些数码照片像素很高,足以帮助检测白内障.黄斑退化.糖尿 ...

  4. mysql binlog恢复

    MySQL Binary Log也就是常说的bin-log, ,是mysql执行改动产生的二进制日志文件,其主要作用有两个: * 数据回复 * 主从数据库.用于slave端执行增删改,保持与maste ...

  5. 【转】Servlet与web.xml的配置

    Web.xml常用元素<web-app><display-name></display-name>定义了WEB应用的名字<description>< ...

  6. QTextCodec::makeDecoder函数,plugins需要是动态链接库

    QT中的QString内容使用Unicode作为文本编码.但是实际系统中通常采用的是其他编码,例如GBK,utf8等.为了便于兼容这些格式,QT中还设置了两个字符串类型: QCString类: C类型 ...

  7. Mysql 按行dump出数据

    mysqldump -u${user} -p${passwd} --skip-extended-insert --database ${dbname} --table ${tablename} > ...

  8. 转:ASP.NET MVC + EF 更新的几种方式

    1.常用 db.Entry(实体).State = EntityState.Modified;db.SaveChanges(); 2.指定更新 db.Configuration.ValidateOnS ...

  9. Java学习-036-JavaWeb_005 -- JSP 动作标识 - forward

    JSP 动作主要作用是根据指定的动作进行相应的处理. 一.param 动作 用来给 HTML 文件和 JSP 文件传递参数的,经常和 forward.include.plugin 动作结合使用,语法格 ...

  10. 给网卡配置10个临时ip地址,但是不配置192.168.17.15这个ip

    给网卡配置10个临时ip地址,但是不配置192.168.17.15这个ip #!/bin/bash `;do ];then continue fi ifconfig eth0:$i .$i netma ...