博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JMS和ActiveMQ学习笔记一
阅读量:4138 次
发布时间:2019-05-25

本文共 2477 字,大约阅读时间需要 8 分钟。

1.为什么异步调用是高效的?

  Systems that rely upon synchronous requests typically have a limited ability to scale because eventually requests will begin to back up, thereby slowing the whole system.
《ActiveMQ in Action》一书在解释同步调用的系统为什么会存在性能问题,或者反过来说为什么异步调用的系统性能要好的时候是这样解释的:同步调用总会有可能出现请求因为没有及时响应而导致阻塞的情况发生!

2.JMS的消息格式

  和所有其他的通信规范一样,JMS也会定义消息的格式,如同http的request和response格式一样,jms的消息也分成header和body两部分:

header部分主要是由预定义属性和一些自定义属性组成,一些重要的预定义属性有:

JMSDestination:消息的目的地

JMSDeliveryMode:消息的投递模式,有两种Persistent和Nonpersistent

JMSExpiration:消息的期限

JMSMessageID:消息的ID

JMSPriority:消息的优先级

....

body部分,JMS定义了六种java类型,它们是:
  1 Message —The base message type. Used to send a message with no payload, only
headers and properties. Typically used for simple event notification.
  2 TextMessage —A message whose payload is a String. Commonly used to send simple
textual and XML data.
  3 MapMessage —Uses a set of name/value pairs as its payload. The names are of
type String and the values are a Java primitive type.
  4 BytesMessage —Used to contain an array of uninterpreted bytes as the payload.
  5 StreamMessage—A message with a payload containing a stream of primitive Java
types that’s filled and read sequentially.
  6 ObjectMessage—Used to hold a serializable Java object as its payload. Usually
used for complex Java objects. Also supports Java collections.

3.消息的发布机制

  所有MOM现在都支持两种消息发布机制:point-to-point和publish-subscribe。

点对点通信机制如下图:


订阅发布通信机制如下图:

补充:关于Request/Response风格的消息通信.


      Although the JMS spec doesn’t define request/reply messaging as a formal messaging domain, it does provide some message headers and a couple of convenience classes for handling basic request/reply messaging.

  JMS没有定义这种风格的通信机制,但是通过一些消息header的属性和工具类是很容易实现这种通信模型的。这里所需要的header主要是JMSReplyTo和JMSCorrelationID两个属性.
The JMSReplyTo specifies the destination where a reply should be sent, and the JMSCorrelationID in the reply message specifies the JMSMessageID of the request message. These headers are used to link the reply message(s) to the original request message.
      JMSReplyTo指明了响应应该送交的地址,很显然这是请求消息要提供的。JMSCorrelationID则用来指明这则消息是回复给那个请求的,因此它应该是响应消息里要提供的。
  The convenience classes for handling basic request/reply are the QueueRequestor and the TopicRequestor. These classes provide a request() method that sends a request message and waits for a reply message through the creation of a temporary destination where only one reply per request is expected.
      而工具类,则是指QueueRequestor和TopicRequestor的request方法,这个方法会发送一个请求消息,然后等待一个响应消息。

转载地址:http://oflvi.baihongyu.com/

你可能感兴趣的文章
Build GingerBread on 32 bit machine.
查看>>
How to make SD Card world wide writable
查看>>
Detecting Memory Leaks in Kernel
查看>>
Linux initial RAM disk (initrd) overview
查看>>
Timestamping Linux kernel printk output in dmesg for fun and profit
查看>>
There's Much More than Intel/AMD Inside
查看>>
apache和tomcat整合
查看>>
java虚拟机错误问题
查看>>
oracle建立表空间
查看>>
oracle分区表的性能提升
查看>>
"Cannot allocate memory" OutofMemory when call Ant to build Polish project in Tomcat
查看>>
dumpcap抓包(python)
查看>>
查看文件是否被其他进程访问
查看>>
字符编码详解
查看>>
python使用dpkt分析wireshak报文(Modbus规约)
查看>>
css中的IFC
查看>>
CentOS 6.5下 mysql用户root登录不了
查看>>
windows + tomcat 部署web服务 http 改为https访问方法
查看>>
Windows系统下Apache 服务器启动以及过程中产生问题的解决办法
查看>>
Oracle服务说明
查看>>