专业做网站的公司 郑州,京东网站建设,wordpress如何添加模板文件夹,义乌对外寻找代加工rabbitmq订单模块RabbitMQ提供了具有可预测且一致的吞吐量和延迟的高可用性#xff0c;可伸缩和便携式消息传递系统。 RabbitMQ是AMQP #xff08;业务消息传递的开放标准#xff09;的领先实现 #xff0c;并且通过适配器支持XMPP#xff0c;SMTP#xff0c;STOMP和HTTP… rabbitmq订单模块 RabbitMQ提供了具有可预测且一致的吞吐量和延迟的高可用性可伸缩和便携式消息传递系统。 RabbitMQ是AMQP 业务消息传递的开放标准的领先实现 并且通过适配器支持XMPPSMTPSTOMP和HTTP来进行轻量级Web消息传递。 这个新模块允许您在Play上的RabbitMQ实例上消费和产生消息 框架应用程序。 安装 play install rabbitmq 组态 module.rabbitmq${play.path}/modules/rabbitmq-0.0.1
rabbitmq.hostlocalhost
rabbitmq.port5672
rabbitmq.userNameguest
rabbitmq.passwordguest
rabbitmq.vhost/
rabbitmq.exchangeTypedirect
rabbitmq.durabletrue
rabbitmq.autoAckfalse
rabbitmq.basicQostrue 定义将由队列使用的消息只是一个简单的POJO public class SampleMessage implements Serializable {/** The field1. */private String field1;/** The field2. */private String field2;/*** Instantiates a new sample message.*/public SampleMessage() {}/*** Instantiates a new sample message.** param field1 the field1* param field2 the field2*/public SampleMessage(String field1, String field2) {super();this.field1 field1;this.field2 field2;}/*** Gets the field1.** return the field1*/public String getField1() {return field1;}/*** Sets the field1.** param field1 the new field1*/public void setField1(String field1) {this.field1 field1;}/*** Gets the field2.** return the field2*/public String getField2() {return field2;}/*** Sets the field2.** param field2 the new field2*/public void setField2(String field2) {this.field2 field2;}/*** To String** see java.lang.Object#toString()*/Overridepublic String toString() {return SampleMessage [field1 field1 , field2 field2 ];}
} 发布消息 public static void publish(String q) {RabbitMQPublisher.publish(myQueue, new SampleMessage(q, q));render(q);} 创建消息使用者 OnApplicationStart(asynctrue)
public class RabbitMQSampleConsumer extends RabbitMQConsumer {/*** Consume Message** see play.modules.rabbitmq.consumer.RabbitMQConsumer#consume(T)*/Overrideprotected void consume(SampleMessage message) {System.out.println(******************************);System.out.println(* Message Consumed: message);System.out.println(******************************);}/*** Name of the Queue that this consumer will be listening to.** return the string* see play.modules.rabbitmq.consumer.RabbitMQConsumer#queue()*/Overrideprotected String queue() {return myQueue;}/*** Return message type.** return the message type* see play.modules.rabbitmq.consumer.RabbitMQConsumer#getMessageType()*/protected Class getMessageType() {return SampleMessage.class;}
} *请注意这是一场戏 作业因此您可以手动启动它也可以使用Play提供的其他注释 例如On或Every。 有关更多信息请参见“ 异步作业”文档 。 Firehose –批量发布消息的另一种方法 OnApplicationStart(async true)
public class RabbitMQSampleFirehose extends RabbitMQFirehose {/** The count. */public int count 0;/*** Get data to be loaded.** param n the n* return the data* throws Exception the exception* see play.modules.rabbitmq.producer.RabbitMQFirehose#getData(int)*/Overrideprotected List getData(int n) throws Exception {if ( count 10 ) {return null;}List results new ArrayList();for (int i 0; i n; i) {results.add(new SampleMessage(field1, field2));count;}return results;}/*** Batch Size - How many records we will select at the time?.** return the int* see play.modules.rabbitmq.producer.RabbitMQFirehose#batchSize()*/Overrideprotected int batchSize() {return 2;}/*** Queue Name.** return the string* see play.modules.rabbitmq.producer.RabbitMQFirehose#queueName()*/Overrideprotected String queueName() {return myQueue;}} *请注意这是一场戏 作业因此您可以手动启动它也可以使用Play提供的其他注释 例如On或Every。 有关更多信息请参见“ 异步作业”文档 。 当然该代码在Github上可用。 现在开始游戏 参考 RabbitMQ Play模块 我们的JCG合作伙伴 Felipe Oliveira在Geeks的 框架 完全在 。 相关文章 Java Code Geeks Andygene Web原型 每个程序员都应该知道的事情 Spring MVC开发–快速教程 SmartGWT入门提供出色的GWT界面 GWT 2 Spring 3 JPA 2 Hibernate 3.5教程 翻译自: https://www.javacodegeeks.com/2011/04/rabbitmq-module-play-framework.htmlrabbitmq订单模块