一、Queue 发送

public class JmsSend {

    public static void main(String[] args) throws JMSException {
ConnectionFactory connectionFactory=new ActiveMQConnectionFactory("tcp://192.168.174.104:61616");
Connection connection = connectionFactory.createConnection(); connection.start(); Session session=connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination queue=session.createQueue("my-queue2"); MessageProducer producer=session.createProducer(queue); for(int i=0 ; i<3 ; i++){
TextMessage message=session.createTextMessage("message"+i);
//message.setStringProperty("queue", "queue"+i);
//message.setJMSType("1");
producer.send(message);
}
session.commit();
session.close(); connection.close(); } }

二、Queue 接收

public class JmsReceiver {
public static void main(String[] args) throws JMSException { ConnectionFactory connectionFactory=new ActiveMQConnectionFactory("tcp://192.168.174.104:61616");
Connection connection = connectionFactory.createConnection();
connection.start(); Session session=connection.createSession(Boolean.FALSE, Session.CLIENT_ACKNOWLEDGE);
Destination queue=session.createQueue("my-queue2"); MessageConsumer consumer = session.createConsumer(queue); int i=0;
while (i<3){
TextMessage message=(TextMessage) consumer.receive();
//System.out.println(message.getStringProperty("queue"));
System.out.println(message.getText());
//session.commit(); if(i==2){
message.acknowledge();
} i++; } session.close();
connection.close(); }
}

ActiveMQ Queue示例的更多相关文章

  1. ActiveMQ使用示例之Queue

    我们使用ActiveMQ为大家实现一种点对点的消息模型. 开发时候,要将apache-activemq-5.12.0-bin.zip解压缩后里面的activemq-all-5.12.0.jar包加入到 ...

  2. ActiveMQ queue 代码示例

    生产者: package com.111.activemq; import javax.jms.Connection; import javax.jms.ConnectionFactory; impo ...

  3. ActiveMQ入门示例

    1.ActiveMQ下载地址 http://activemq.apache.org/download.html 2.ActiveMQ安装,下载解压之后如下目录

  4. JMS消息队列之ActiveMQ简单示例

      废话不多说,在进入主题前先看一张图,对ActiveMQ有个大体的了解:   下面进入主题:   1.添加需要的maven依赖 <!-- active mq begin --> < ...

  5. ActiveMQ queue和topic,持久订阅和非持久订阅

    消息的 destination 分为 queue 和 topic,而消费者称为 subscriber(订阅者).queue 中的消息只会发送给一个订阅者,而 topic 的消息,会发送给每一个订阅者. ...

  6. 【分布式系列之ActiveMq】ActiveMq入门示例

    前言 github地址:https://github.com/AndyFlower/web-back/tree/master/ActiveMq01 下载ActiveMQ :http://activem ...

  7. ActiveMQ使用示例之Topic

    非持久的Topic消息示例  对于非持久的Topic消息的发送基本跟前面发送队列信息是一样的,只是把创建Destination的地方,由创建队列替换成创建Topic,例如: Destination d ...

  8. ActiveMQ Queue vs Topic vs VirtualTopic

    之前写过一篇文章讨论VirtualTopic,但觉得不够透彻,这里再根据实验结果进行一次横向对比破除模糊和选择困难症. 文章中核心对比要素是:消息副本和负载均衡 Queue的特点和优势 ActiveM ...

  9. ActiveMQ queue 分页

    分页:即获取部分数据,queue按页从message cursor读取消息,然后分发给consumer. 页大小: public abstract class BaseDestination impl ...

随机推荐

  1. ListView中的Item不能点击的解决方法

    有时,为了实现某种功能,在Android程序中会考虑在ListView的每一个Item中添加一个Button(或ImageButton等). 但是,这样会出现一个问题: 当同时设置了Button的on ...

  2. nrm切换npm包源

    nrm可以随时切换npm包的源 npm install -g nrm 安装nrm完成 查看nrm源 nrm ls 切换源 npm use npm #也可以切换成其他源 

  3. Redis Desktop Manager的下载及安装

    一.下载Redis Desktop Manager 1. Redis Desktop Manager 的下载路径 (1)https://pan.baidu.com/s/1Jvr9MbgFn4UJh4M ...

  4. arcgis python 不知道一个工具怎么用

    完整的工具帮助信息 import arcpy print(arcpy.Usage("Buffer_analysis")) print(arcpy.Usage("MakeF ...

  5. 组合数学---P1358 扑克牌

    P1358 扑克牌 题解 组合数学 Π c[剩余未选牌数][ai] ( i = 1,2,...,m ) 注意 组合数也要取模,不然数字太大会炸 组合数的具体实现就是Dp啊 代码 #include< ...

  6. teraflop级、TFLOPS、TOPS

    FLOPS 每秒浮点运算次数,TFLOPS表示每秒万亿(10^12)次浮点计算: TFLOPS是floating point operations per second 每秒所执行的浮点运算次数. 1 ...

  7. 利用redis实现分布式事务锁,解决高并发环境下库存扣减

    利用redis实现分布式事务锁,解决高并发环境下库存扣减   问题描述: 某电商平台,首发一款新品手机,每人限购2台,预计会有10W的并发,在该情况下,如果扣减库存,保证不会超卖 解决方案一 利用数据 ...

  8. Linux输出信息并将信息记录到文件(tee命令)

    摘自:https://www.jb51.net/article/104846.htm 前言 最近工作中遇到一个需求,需要将程序的输出写到终端,同时写入文件,通过查找相关的资料,发现可以用 tee 命令 ...

  9. IDEA中提示Error:java: Compilation failed: internal java compiler error

    解决办法:File-->Setting...-->Build,Execution,Deployment-->Compiler-->Java Compiler 设置相应Modul ...

  10. videojs改变音量大小

    <audio id=example-video preload="auto" class="video-js vjs-default-skin" type ...