HornetQ Topic/queue for Clojure

Source: Internet
Author: User

HornetQ Topic/queue for Clojure


1. HornetQ Overview

HornetQ is an asynchronous messaging system that supports clustering and multiple protocols that can be embedded and high-performance. HornetQ fully supports JMS,HornetQ not only supports JMS1.1 API but also defines its own message API, which maximizes HornetQ 's performance and flexibility. More agreements will be supported by HornetQ in the near future.  

2. HornetQ features

(1)HornetQ has ultra-high performance,HornetQ performance in persistent messaging can easily exceed the performance of other common non-persistent messaging engines. Of course, the performance ofHornetQ 's non-persistent messages will perform better!

(2)HornetQ full use of POJO, pure POJO design so that HornetQ can rely on a third-party package as little as possible. Design patterns, such as theHornetQ design intrusion is also minimal. The HornetQ can be run independently or integrated with other Java application servers.

(3)HornetQ has a perfect error handling mechanism,HornetQ provides server replication and fault auto-transfer function, which can eliminate the loss of messages or multiple duplicate information caused by server error.

(4)HornetQ provides a flexible clustering feature that enables you to enjoy the performance gains of message load balancing by creating HornetQ clusters. You can also form a global messaging network through clustering. You can also configure message routing flexibly.

(5)HornetQ has a powerful management function. HornetQ provides a large number of management APIs and monitoring servers. It can seamlessly integrate with application servers and work together in an HA environment.


Note: The above excerpt from Baidu Encyclopedia Http://baike.baidu.com/view/4895723.htm?fr=aladdin


3. the main differences between Topic and Queue

First, let's take a look at several concepts:

(1) Destination (destination): The destination where the message is sent, and also the channel for message delivery. It could be a queue or a topic.

(2) Producer (producer): The creator of the message. The producer of the message is only responsible for sending messages to the destination (destination), leaving it behind and doing other things. And how the message will eventually be handled depends on the consumer of the message.

(3) Consumer (consumer): The consumer of the message. Consumers can subscribe (or listen to) a destination, and when a message arrives, the message can be processed accordingly. You can also determine whether you want to accept this message based on the characteristics of the message.

In fact, the general flow of the message service is simple, the message producer sends a message to the message queue (or subject), and the consumer gets the message from the queue (or subject). Producers and consumers do not interfere.

Here's the difference between the topic and the queue:

Queue : That is, Message Queuing. A queue can have multiple consumer to listen (listen). But a message can only be received by one consumer, that is, if a message is dropped by a consumer, the other consumer will not receive the message. Also, if a message does not have a consumer available, the message is kept in the queue until consumer responds to it, that is, the queue message is not lost. The message delivery pattern for a queue is a point-to-point (point-to-point) delivery pattern.

Topic: That is the subject. the message Publisher publish the message to the subject, and the consumer subscribe the subject (subscription). A topic can have multiple consumer subscriptions to it. The message published by the publisher is broadcast, and the consumer who subscribes to the topic receives the message (a copy of the message is held) and can respond to the message. There is no guarantee in topic that every message can be received by the consumer. If a message does not have a consumer listening, the topic will be lost. The message delivery pattern for topic is publish/subcribe (Publish/subscribe) mode.


4. Simple application (using Immutant's API)

* * Implementing asynchronous Message Queuing with queue

(1) Create a message queue:

(Require ' [Immutant.messaging:as m])

(Def q (m/queue "Test-queue")

(2) Post a message

(M/publish Q "a message")

(3) Custom Message handler, here simply print out the message

(Defn Msg-handle

[MSG]

(PRN msg))

(3) Listening to Message Queuing, registering handler functions

(Def listener (M/listen Q # (msg-handle%)))

(4) Turn off monitoring

(Stop Listner)

(. Close listener)


* * Synchronous Message Queuing with queue implementation

(1) Defining Message Queuing

(Def sync-q (m/queue "Sync-q")

(2) Customizing message answering methods

(Def Respinder (M/respond Sync-q Inc)

(3) Send a message

@ (m/request sync-q 1)

Note: The request will wait until the message is answered before it returns, otherwise it remains blocked.


* * Implementing asynchronous messages with topic

(1) Definition topic

(Def t (m/topic "test-topic"))

(2) post a topic message

(M/publish T "a message")

(3) Subscription topic, Registration processing function

(M/subscribe T "subscriber-name" # (msg-handle%)

(4) Unsubscribe

(M/unsubscribe t Subscriber-name)


HornetQ Topic/queue for Clojure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.