分布式-信息方式-ActiveMQ构建应用
ActivemQ构建应用
Broker:相当于一个 ActiveMQ服务器实例
命令行启动参数示例如下:
1: activemq start:使用默认的 actived.xml来启动
2: activemq start xbean:file: ../onf/ actived-2.xml:使用指定的配置文件
来启动
3:如果不指定file,也就是 xbean: activemq-2.xml,那么xml必须在 classpath下面
用 ActiveMQ米构建Java应用
这里主要将用 Activemq broken作为独立的消息服务器来构建JAVA应用
ActiveMQ也支持在vm中通信基于嵌入式的 broker,能够无缝的集成其它Java应用
■嵌入式 Broker启动
1: Broker service启动 broker,示例如下:
BrokerService broker=new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://localhost:61616");
broker.start();
package com.mq.test.activeMQ; import java.net.URI; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.omg.CORBA.portable.ApplicationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class InnerBroker {
public static void main(String[] args) throws Exception {
BrokerService broker=new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://localhost:61616");
broker.start(); }
}
2: BrokerFactory启动 broker,示例如下:
String Uri ="properties:broker.properties";
BrokerService broker1 =BrokerFactory.createBroker(new URI(Uri));
broker1.addConnector("tcp://localhost:61616");
broker1.start();
broker.properties
useJmx=true
persistent=false
brokerName=cheese
package com.mq.test.activeMQ; import java.net.URI; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.omg.CORBA.portable.ApplicationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class InnerBroker {
public static void main(String[] args) throws Exception {
String Uri ="properties:broker.properties";
BrokerService broker1 =BrokerFactory.createBroker(new URI(Uri));
broker1.addConnector("tcp://localhost:61616");
broker1.start(); }
}
3:利用Spring集成Broker,Spring的配置文件如下:
<bean id="broker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value="myBroker" />
<property name="persistent" value="false"></property>
<property name="transportConnectorURIs" >
<list>
<value>tcp://localhost:61616</value>
</list>
</property>
</bean>
package com.mq.test.activeMQ; import java.net.URI; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.omg.CORBA.portable.ApplicationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class InnerBroker {
public static void main(String[] args) throws Exception { ApplicationContext ctx =new ClassPathXmlApplicationContext("applicationContext.xml");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-autowire="byName" default-lazy-init="false"> <bean id="broker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value="myBroker" />
<property name="persistent" value="false"></property>
<property name="transportConnectorURIs" >
<list>
<value>tcp://localhost:61616</value>
</list>
</property>
</bean> </beans>
或者配置 BrokerFactoryBean,示例如下:
<beans>
<bean id=broker class="org. apache. activemq. xbean. BrokerFactoryBean">
<Property name="config" value="resources/activemq-simple.xml"/>
<property name="start" value="true"/>
</bean>
</beans>
■ ActiveMQ的启动:
1:可以通过在应用程序中以编码的方式启动 broker,例如: broker. start(
如果需要启动多个 broker,那么需要为 broker设置一个名字。例如
BrokerService broker= new BrokerService();
broker.setName("fred")
broker.addConnector("tcp: //localhost: 61616")
broker.start
2:还可以通过 spring来启动,前面已经演示过了
分布式-信息方式-ActiveMQ构建应用的更多相关文章
- 分布式-信息方式-ActiveMQ的Message dispatch高级特性之(指针) Message cursors
Message dispatch高级特性之 Message cursors概述 ActiveMQ发送持久消息的典型处现方式是:当消息的消费者准备就绪时,消息发送系统把存储的 消息 ...
- 分布式-信息方式-ActiveMQ的Destination高级特性3
虚拟destination用来创建逻辑destination,客户端可以通过它来生产和消费消息,它会把消息映射到物理destination. ActiveMQ支持2种方式: 1:虚拟主题(Virtua ...
- 分布式-信息方式-ActiveMQ的Destination高级特性1
ActiveMQ的Destination高级特性 Destination高级特性----->Composite Destinations 组合队列Composite Destinations : ...
- 分布式-信息方式-ActiveMQ的集群
ActiveMQ的集群Queue consumer clusters ActiveMQ支持 Consumer对消息高可靠性的负载平衡消费,如果一个 Consumer死掉,该消 ...
- 分布式-信息方式-ActiveMQ静态网络连接的容错
容错的链接Failover Protocol 前面讲述的都是client配置链接到指定的 broker上.但是,如果 Broker的链接失败怎么办呢?此时, Client有两个选项:要么立刻死掉,要么 ...
- 分布式-信息方式-ActiveMQ的消息存储持久化
ActiveMQ的消息存储持久化■概述ActiveMQ不仅支持 persistent和 non-persistent两种方式,还支持消息的恢复( recovery)方式PTPQueue的存储是很简单的 ...
- 分布式-信息方式-ActiveMQ基础
ActiveMQ简介 ActiveMQ是什么ActiveMQ是Apache推出的,一款开源全支持JMS.1和J2EE1.4范的JMS Provider实现的信息中间件.(message oriente ...
- 分布式-信息方式-ActiveMQ的Destination高级特性2
使用filtered destinations,在xml配置如下: <destinationInterceptors> <virtualDestinationInterceptor& ...
- 分布式-信息方式-ActiveMQ的动态网络链接
ActiveMQ的动态网络链接多播协议 multicast ActiveMQ使用 Multicast协议将一个 Service和其他的 Broker的 Service连接起来,IPmulticast是 ...
随机推荐
- git删除已经push的远程文件或文件夹
在使用git提交项目时,有时候会误提交一下文件,比如:*.iml,*.project,*.settings,.idea/*等文件,有时候这些不需要提交的文件可以加入到.gitignore,在提交的时候 ...
- 分布式---Raft算法
6.Raft Raft也是分布式一致性协议,主要是用来竞选主节点. 单个Candidate的竞选 有三种节点:Follower,Candidate和Leader.Leader会周期性的发送心跳 ...
- 数据绑定-POJO对象绑定参数
测试: 效果:
- luogu题解 UVA534 【Frogger--最小瓶颈边
题目链接: https://www.luogu.org/problemnew/show/UVA534 Update 6.18 多点对最短瓶颈路算法:https://www.cnblogs.com/Ry ...
- vue-时间插件,效果见图
<template> <div class="select-time-wrapper"> <h5 class="titie"> ...
- java文档注释规范(一)
https://blog.csdn.net/huangsiqian/article/details/82725214 Javadoc工具将从四种不同类型的“源”文件生成输出文档:Java语言类的源文件 ...
- LRU算法介绍和在JAVA的实现及源码分析
一.写随笔的原因:最近准备去朋友公司面试,他说让我看一下LRU算法,就此整理一下,方便以后的复习. 二.具体的内容: 1.简介: LRU是Least Recently Used的缩写,即最近最少使用. ...
- idea中 参数没有描述报错 @param XX tag description is missing错误,去除黄色警告
最近在使用idea开发工具,在方法备注中参数没有描述报错就会报一些黄色警告: @param XX tag description is missing,下面展示去除黄色警告的方法 File--sett ...
- traceback:让你更加灵活地处理python的异常
异常 异常在python中是屡见不鲜了,程序在执行到某一行代码时,发现有问题,比如数组索引越界,变量没有定义啊等等,此时就会抛出异常 捕获异常 在python,一般都是使用try···except来对 ...
- 从一道索引数据结构面试题看B树、B+树
题目1: Mysql数据库用过吧?l里面的索引是基于什么数据结构. 答:主要是基于Hash表和B+树 题目2: 很好请你说一下B+树的实现细节是什么样的?B-树和B+树有什么区别?联合索引在B+树中如 ...