一、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. Multiple commands produce "*.framework"

    参考链接记录个问题,这是xcode10后新build系统导致的,新系统帮我们检查了很多东西,最优化我们的构建, 两种方案 1.用旧的系统(不推荐)   2.这个是build setting->b ...

  2. Apache Flink - 数据流容错机制

    Apache Flink提供了一种容错机制,可以持续恢复数据流应用程序的状态.该机制确保即使出现故障,程序的状态最终也会反映来自数据流的每条记录(只有一次). 从容错和消息处理的语义上(at leas ...

  3. git clone 报“The project you were looking for could not be found.”

    因为自己的项目不止一个 又有自动保存git密码的功能,当clone第二个项目的时候就报了如下错误 之前一直是找到钥匙串删除,发现有时候并没有效果.今天在网上搜了一下 发现了一个新的解决办法 在项目前面 ...

  4. idea备忘

    1.idea 最近打开的文件个数 File->Settings->Editor->General->Editor Tabs->Tab Closing Policy-> ...

  5. 如何查看SWT源代码和帮助文档

    如何查看SWT源代码https://blog.csdn.net/wzq__janeGreen_/article/details/80068998

  6. NTC热敏电阻基础以及应用和选择(转)

    源:NTC热敏电阻基础以及应用和选择 NTC被称为负温度系数热敏电阻,是由Mn-Co-Ni的氧化物充分混合后烧结而成的陶瓷材料制备而来,它在实现小型化的同时,还具有电阻值-温度特性波动小.对各种温度变 ...

  7. keras损失函数

    keras文档:  http://keras.io/objectives/ mean_squared_error / mse  均方误差,常用的目标函数,公式为((y_pred-y_true)**2) ...

  8. Qt编写自定义控件47-面板区域控件

    一.前言 在很多web网页上,经常可以看到一个设备对应一个面板,或者某种同等类型的信息全部放在一个面板上,该面板还可以拖来拖去的,这个控件首次用在智能访客管理平台中,比如身份证信息一个面板,访客信息一 ...

  9. eclipse spring3.X redis 整合-配置

    花了一天时间折腾redis的配置 用到的jar spring 3.1.1 aopalliance-1.0.jar commons-pool2-2.3.jar jedis-2.7.2.jar sprin ...

  10. maven中央仓库的配置在哪里?superpom是什么?中央仓库查找三方包

    maven的superpom 每个项目都默认继承的pom 位置 $M2_HOME/lib/maven-model-builder.jar 使用tar -xvf解压后,grep -r central 搜 ...