RabbitMQ播放模塊! 構架

RabbitMQ提供了具有可預測且一致的吞吐量和延遲的高可用性,可伸縮和便攜式消息系統。 RabbitMQ是AMQP (業務消息傳遞的開放標準)的領先實現 ,并且通過適配器支持XMPP,SMTP,STOMP和HTTP來進行輕量級Web消息傳遞。

這個新模塊允許您在Play的RabbitMQ實例上使用和產生消息! 框架應用程序。

安裝

play install rabbitmq

組態

module.rabbitmq=${play.path}/modules/rabbitmq-0.0.1
rabbitmq.host=localhost
rabbitmq.port=5672
rabbitmq.userName=guest
rabbitmq.password=guest
rabbitmq.vhost=/
rabbitmq.exchangeType=direct
rabbitmq.durable=true
rabbitmq.autoAck=false
rabbitmq.basicQos=true

定義將由隊列使用的消息(只是一個簡單的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(async=true)
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.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/374656.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/374656.shtml
英文地址,請注明出處:http://en.pswp.cn/news/374656.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Cyclic Nacklace - HDU 3746(next求循環節)

題目大意&#xff1a;給你一些串&#xff0c;問如果想讓這個串里面的循環節至少循環兩次&#xff0c;需要添加幾個字符&#xff08;只能在最前面或者最后面添加&#xff09;。比如ababc 需要添加5個就是添加ababc。 分析&#xff1a;其實字符串的長度len-next[len] 最小循環節…

Xuggler開發教程

大家好&#xff0c; 在這篇文章中&#xff0c;我想介紹JavaCodeGeeks上的一些很酷的新教程。 他們將討論與Xuggler &#xff0c; FFmpeg和Wowza進行媒體&#xff08;音頻/視頻&#xff09;操縱的方式。 我將在這篇文章中跟蹤所有相關的教程。 您可以通過查看Pat較早的關于使用…

739. 每日溫度

請根據每日 氣溫 列表 temperatures &#xff0c;請計算在每一天需要等幾天才會有更高的溫度。如果氣溫在這之后都不會升高&#xff0c;請在該位置用 0 來代替。 代碼一 單調棧 class Solution {public int[] dailyTemperatures(int[] temperatures) {int length temperatur…

一個非常好的性格切割問題

結伙stackoverflow看到一道非常不錯的問題。遂拿來分享之。 題目要求&#xff1a;我有一個非常長的字符串&#xff1a; String s1"This is my world. This has to be broken." 我要把上面的字符串打亂以固定的長度&#xff08;比如10&#xff09;使得輸出為&#xff…

Cajo,用Java完成分布式計算的最簡單方法

摘自Jonas Boner在2006年5月1日發布在TheServerSide.com上的文章“ Distributed Computing Easy”中的介紹部分&#xff1a; 分布式計算在企業應用程序開發世界中變得越來越重要。 如今&#xff0c;開發人員不斷需要解決以下問題&#xff1a;如何通過將應用程序擴展到單個節點之…

Java中Integer.parseInt()用法

1.先看看該方法的實現 public static int parseInt(String s) throws NumberFormatException {return parseInt(s,10);}2.事實上他可以有兩個參數&#xff0c; public static int parseInt(String s,int radix)意味著將字符串s按照radix進制轉換成整數。太抽象了&#xff0c;…

關于maven相互依賴的工程部署問題

環境&#xff1a;win7 64位&#xff0c;myeclipse10.6&#xff0c;eclipse4.5&#xff0c;都配置了svn插件 問題描述&#xff1a;1、工程模塊化之后都是通過pom配置model來關聯的&#xff0c;svn提交之后&#xff0c;通過myeclipse的svn‘檢出為項目’&#xff0c;依賴的子工程…

什么是JAR包?

jar包就是別人已經寫好的一些類&#xff0c;然后將這些類進行打包&#xff0c;你可以將這些jar包引入你的項目中&#xff0c;然后就可以直接使用這些jar包中的類和屬性了&#xff0c;這些jar包一般都會放在lib目錄下的 轉載于:https://www.cnblogs.com/wulianshang/p/5513474.h…

....

輸入流和輸出流相對于內存設備而言. 將外設中的數據讀取到內存中:輸入將內存的數寫入到外設中&#xff1a;輸出。 字符流的由來&#xff1a;其實就是&#xff1a;字節流讀取文字字節數據后&#xff0c;不直接操作而是先查指定的編碼表。獲取對應的文字。在對這個文字進行操作。…

DataNucleus 3.0與Hibernate 3.5

如官方產品站點所述&#xff0c; DataNucleus Access Platform是現有的最符合標準的開源Java持久性產品。 它完全符合JDO1 &#xff0c; JDO2 &#xff0c; JDO2.1 &#xff0c; JDO2.2 &#xff0c; JDO3 &#xff0c; JPA1和JPA2 Java標準。 它還符合OGC簡單功能規范&#xf…

手工內存管理規則的總結

1.如果需要保持一個對象不被銷毀,可以使用retain.在使用完對象后,需要使用release銷毀 2.給對象發送release消息并不會銷毀對象,只有當這個對象的引用計數減為0時,對象才會被銷毀.然后系統會發送dealloc消息給這個對象用于釋放它的內存. 對使用了retain或者copy,mutableCopy,al…

Java 字符,整型,字符串三者轉換

1.整型 —> 字符型 先把整型轉化為字符串&#xff0c;再把字符串轉化為字符 //整型 ---> 字符型 toString(int n).charAt(int index) System.out.println(Integer.toString(20).charAt(0));2.整型 —> 字符串 //整型 ---> 字符串 Inte…

AngularJS 的常用特性(二)

3、列表、表格以及其他迭代型元素 ng-repeat可能是最有用的 Angular 指令了&#xff0c;它可以根據集合中的項目一次創建一組元素的多份拷貝。 比如一個學生名冊系統需要從服務器上獲取學生信息&#xff0c;目前先把模型之間定義在 JavaScript 代碼里面&#xff1a; 1 var stud…

Ruby,Python和Java中的Web服務

今天&#xff0c;我不得不準備一些示例來說明Web服務是可互操作的。 因此&#xff0c;我已經使用Metro使用Java創建了一個簡單的Web服務&#xff0c;并在Tomcat上啟動了它。 然后嘗試使用Python和Ruby消耗它們。 這是全部完成的過程… Java中的Web服務 我從Java中的簡單Web服…

bzoj4199: [Noi2015]品酒大會

題面見http://uoj.ac/problem/131 一道后綴數組題 先求出height&#xff0c;然后從大到小枚舉每個height。 然后對于每個height值&#xff0c;兩端的集合中任意一對后綴的LCP都是這個height。 我們統計答案之后合并兩端的集合&#xff0c;用并查集維護即可。 1 #include<cst…

css中position初解

positon:static|absolute|relative|fiexd 1、static為默認值&#xff0c;沒有定位&#xff0c;元素出現在正常的文檔流中&#xff0c;忽略left,right,top,bottom,i-index值。 2、absolute為絕對定位&#xff0c;通過left,top等值對元素進行定位&#xff0c;定位時如果父元素的p…

零XML的Spring配置

Tomasz Nurkiewicz是我們的JCG合作伙伴之一&#xff0c;也是Spring框架的堅定支持者&#xff0c;在他的最新文章中描述了如何在不使用XML的情況下配置Spring應用程序。 注解方法在頂部。 查看他的教程&#xff1a; 沒有XML的Spring框架...根本&#xff01; 翻譯自: https://ww…

用動畫切換按鈕的狀態

用動畫切換按鈕的狀態 效果 源碼 https://github.com/YouXianMing/UI-Component-Collection // // BaseControl.h // BaseButton // // Created by YouXianMing on 15/8/27. // Copyright (c) 2015年 YouXianMing. All rights reserved. //#import <UIKit/UIKit.h> c…

iOS開發之學前了解

學iOS開發能做什么&#xff1f; iOS開發需要學習哪些內容&#xff1f; 先學習什么&#xff1f; 不管你是學習android開發還是iOS開發 都建議先學習UI&#xff0c;原因如下&#xff1a; UI是app的根基&#xff1a;一個app應該是先有UI界面&#xff0c;然后在UI的基礎上增加實用功…

力扣gupiao

給定一個數組 prices &#xff0c;它的第 i 個元素 prices[i] 表示一支給定股票第 i 天的價格。 你只能選擇 某一天 買入這只股票&#xff0c;并選擇在 未來的某一個不同的日子 賣出該股票。設計一個算法來計算你所能獲取的最大利潤。 返回你可以從這筆交易中獲取的最大利潤。…