| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
fmms
13年前发布

JMS服务器 DropboxMQ

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.open-open.com/lib/view/home/1336702375875

 本文由用户 fmms 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1336702375875.html
JMS 消息系统