cht台灣個人Log4Q
adm Find login register

[note] 註解一下 ActiveMQ 提供的 JMS FAQ

qrtt1

joined: 2007-10-02
posted: 82
promoted: 18
bookmarked: 5
藍星
1subject: [note] 註解一下 ActiveMQ 提供的 JMS FAQPromote 0 Bookmark 02008-06-01quote  

*. Can I modify messages on a queue ?

JMS 訊息一旦被送出就是不可變的,如果有需要改變那麼應該由 consumer 塞選後刪除再發送修改後的訊息。不論您有幾個 Message Queue 都應該避免到重送時可能形成的無窮回圈(您可以試著使用 JMS header 避免這個問題)


*. Can I send and receive messages concurrently on one JMS Connection ?

嚴格來說,每一個 producer 在並行的情況下應該使用各自的 JMS Session
.... ???? (看不太懂..XD)


*. Can you browse a topic ?

您可以瀏覽 queue,但您能瀏覽 topic 嗎? 這是不需要的,即使您瀏覽了每一個 topic 也不會影響其他 consumer,您只要做 subscribe 的動作即可收到 topic


*. How do durable queues and topics work ?

(這個 FAQ 出現二個概念 Durable queues 與 Non-durable queues)


*. How do I consume a specific message

如果要改變 message 被消耗的順序,那可能要實作一個 selector 比對特定的 JMSMessageID 並消耗它

(所以看起來 selector 出現很多次,可能也是 JMS 實作相關的概念)


*. How do I get started with JMS

它建議我去看 Sun 的教學 http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JMS.html#wp84181

不過它也提供一個 DSL 的方案,使用 Apache Camel http://activemq.apache.org/camel/


*. How do I make messages durable ?

關鍵概念 Durability 又出現啦。看來他不只和 JMS Server 端有關,Client 的狀態也能是 Durability 的!? 這裡的解說是設定 MessagerProducer 送出的訊息為 Durability

MessageProducer producer = ...;
producer.setDeliveryMode(DeliveryMode.PERSISTENT);


*.  How do I send messages to different Destinations from a single MessageProducer ?

建立一個沒有預設目的的 MessageProducer 然後在每一次送出時指定。
(這是什麼時候特別有用呢?)


*. How do I use JMS efficiently ?
(這是 Performance Tuning 的主題,會用了再回頭看吧 :P)


*. How does a Queue compare to a Topic ?
(這是名詞比較)

在 JMS 的實作, Topic 的語意為出版(publish)與訂閱(subscribe)。當你出版一個訊息,所有的訂閱者都能收到。

而 Queue 的實作對 JMS 來講是 load blancer 的語意。單一的訊息將被一個 concumer 收到。如果沒有 consumers 存在,那麼訊息會被保留到有 consumers 能接收為止。

假設有 consumer 收到訊息沒有回傳 ack,那訊息會被重送至另一個 consumer (<-- 這句很詭異啊!!!)

If a consumer receives a message and does not acknowledge it before closing then the message will be redelivered to another consumer.

一個 Queue 有很多訊息傳送對象 - consumers,它能對所有的可用的 consumers 做平衡負載。

A queue can have many consumers with messages load balanced across the available consumers.

所以 Queue 被實作為可信的 load balancer


*. How does ConnectionFactory relate to the Broker?

ConnectionFactory 在規格書上是 client 端用來建立連線至 JMS Broker 的介面

(broker 也出現很多次了 XD)

Broker 能以網路服務的形式或 JVM 內的程序存在作為 Message Provider。所以您可以想成 ConnectionFactory 是 client 端用來發送或接受訊息的 API,而 Broker 就是 Server 端的實作

See Also

    * How do I create new destinations
    * How do I embed a Broker inside a Connection
    * What are administered objects

(這 See As 可能會用到 :P)


*. How does JMS compare with email
這個QA在強調 performance 與不同等級的訊息

<%
JMS has a bunch of different qualities of service (durable v non-durable, queue v topic) designed for very high performance messaging with low latency together with reliability
%>

<%
The main reasons for using JMS is performance (throughput & latency), together with support for transactions & XA together with avoiding duplicates and message loss.
%>


*. How should I implement request response with JMS?
(有很完整的範例講怎麼實作 request response)


*. How to unit test JMS code ?
(unit test 的方法)


*. Multiple consumers on a queue ?
(這是比較特殊的需求,通常一個 queue 只有一個 consumer)


*. Should I use transactions ?
(交易管理,等上手了再來看 XD)


*. Should I use XA ?
(糟! 完全不能進入狀況@@ 好像也和交易有關,副標有 two phase commit)

cht台灣個人Log4Q
adm Find login register
views:5744