JMS服務器 DropboxMQ

fmms 12年前發布 | 16K 次閱讀 JMS 消息系統

DropboxMQ 是一個使用文件系統來存儲和發布消息的 JMS 服務器。

快速入門指南:

Producing or Consuming Messages (Common Tasks)

Whether producing or consuming messages, DropboxMQ applications need to do some common tasks before getting to the nuts and bolts of producing or consuming.

1. Creating a Dropbox

Creating a dropbox is as easy as creating a handful of directories in a shared directory known as the root directory. Still the preferred method for creating both queue and topic dropboxes is to use the create-dropbox script as described in the Administrative Guide.

2. Gathering the Jars

DropboxMQ only requires three jars. dropboxmq-0.5.jar, connector-api-1.5.jar and commons-logging-1.1.jar are all included in the DropboxMQ download.

3. JNDI Lookups

A JNDI lookup is the preferred method for retrieving ConnectionFactory and Destination objects. The first step of a JNDI lookup is creating a InitialContext and the environment properties provided to the InitialContext constructor are the primary mechanism for configuring DropboxMQ. See the complete list of JNDI properties on the Configuration Guide.

Properties properties = new Properties();// properties.load() would probably be more suitable properties.setProperty( Context.INITIAL_CONTEXT_FACTORY,
        "net.sf.dropboxmq.jndi.InitialContextFactoryImpl" );
properties.setProperty( "net.sf.dropboxmq.root", "/dropboxmq" );
InitialContext initialContext = new InitialContext( properties );

ConnectionFactory connectionFactory
        = (ConnectionFactory)initialContext.lookup( "ConnectionFactory" );
Destination destination
        = (Destination)initialContext.lookup( "TestQueue1" ); 

4. Creating a Connection and a Session

Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(
        false, Session.AUTO_ACKNOWLEDGE ); 

Producing a Message

MessageProducer producer = session.createProducer( destination );
TextMessage message = session.createTextMessage( "Hello World!" );

producer.send( message ); 

After executing the above code, you will notice a new file in /dropboxmq/TestQueue1/incoming/target. The name of file will be something similar to 4.1140911283485000-1299715532.T. For an explaination of each of the fields contained in the filename look here. Also note that the contents of the file are exactly the text of the TextMessage ("Hello World!").

Consuming a Message

connection.start();

MessageConsumer consumer = session.createConsumer( destination );
TextMessage message = (TextMessage)consumer.receiveNoWait();

System.out.println(
        message == null ? "No message found" : message.getText() ); 

That's it! You will notice that after executing this code the message file that was in the target directory is now in the processed directory. For a complete and compile-able listing of the code above look here.


 

項目主頁:http://www.baiduhome.net/lib/view/home/1336702375875

 本文由用戶 fmms 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!