当前位置: 首页 > news >正文

wordpress建立手机网站广州的百度推广公司

wordpress建立手机网站,广州的百度推广公司,网络平台运营方案,做伊瑞尔竞技场的网站ActiveMQ 安装 下载网址:ActiveMQ 一定要和自己安装的jdk版本匹配,不然会报错 下载到本地之后解压缩 有可能端口号被占用 解除端口号占用,参考:Windows_端口被占用 打开cmd 查询所有的端口号 netstat -nao查询指定端口号 n…

ActiveMQ

安装

下载网址:ActiveMQ

一定要和自己安装的jdk版本匹配,不然会报错

在这里插入图片描述
下载到本地之后解压缩

在这里插入图片描述
在这里插入图片描述
有可能端口号被占用

在这里插入图片描述

解除端口号占用,参考:Windows_端口被占用

打开cmd

查询所有的端口号

netstat -nao

在这里插入图片描述

查询指定端口号

netstat -ano|findstr 5672

查询什么程序在占用

tasklist | findstr "4756"

在这里插入图片描述

打开任务管理器看看这个程序

在这里插入图片描述

erl.exe是什么进程

Erlang 的执行程序,Erlang一种编程语言,多用于并发和分布式系统,现在最广泛使用在消息队列里面。

安装RabbitMQ的好像就是安装的这个,看来是RabbitMQ把这个端口给占用掉了,换个端口号

在这里插入图片描述

将5672改成55672

在这里插入图片描述

网址:http://localhost:8161/admin/

用户名:admin

密码:admin

在这里插入图片描述
成功。

使用

参考:消息队列之 ActiveMQ

在这里插入图片描述

Java访问ActiveMQ实例

在这里插入图片描述

引入依赖
		<dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-all</artifactId><version>5.15.2</version></dependency>
消息生产者
package mq.activeMQ;import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;import javax.jms.*;public class TopicPublisher {/*** 默认用户名*/public static final String USERNAME = ActiveMQConnection.DEFAULT_USER;/*** 默认密码*/public static final String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;/*** 默认连接地址*/public static final String BROKER_URL = ActiveMQConnection.DEFAULT_BROKER_URL;public static void main(String[] args) {//创建连接工厂ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_URL);try {//创建连接Connection connection = connectionFactory.createConnection();//开启连接connection.start();//创建会话,不需要事务Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//创建 Topic,用作消费者订阅消息Topic myTestTopic = session.createTopic("activemq-topic-test1");//消息生产者MessageProducer producer = session.createProducer(myTestTopic);for (int i = 1; i <= 3; i++) {TextMessage message = session.createTextMessage("发送消息 " + i);producer.send(myTestTopic, message);}//关闭资源session.close();connection.close();} catch (JMSException e) {e.printStackTrace();}}
}
消息消费者
package mq.activeMQ;import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;import javax.jms.*;public class TopicSubscriber {/*** 默认用户名*/public static final String USERNAME = ActiveMQConnection.DEFAULT_USER;/*** 默认密码*/public static final String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;/*** 默认连接地址*/public static final String BROKER_URL = ActiveMQConnection.DEFAULT_BROKER_URL;public static void main(String[] args) {//创建连接工厂ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_URL);try {//创建连接Connection connection = connectionFactory.createConnection();//开启连接connection.start();//创建会话,不需要事务Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);//创建 TopicTopic myTestTopic = session.createTopic("activemq-topic-test1");MessageConsumer messageConsumer = session.createConsumer(myTestTopic);messageConsumer.setMessageListener(new MessageListener() {@Overridepublic void onMessage(Message message) {try {System.out.println("消费者1 接收到消息:" + ((TextMessage) message).getText());} catch (JMSException e) {e.printStackTrace();}}});MessageConsumer messageConsumer2 = session.createConsumer(myTestTopic);messageConsumer2.setMessageListener(new MessageListener() {@Overridepublic void onMessage(Message message) {try {System.out.println("消费者2 接收到消息:" + ((TextMessage) message).getText());} catch (JMSException e) {e.printStackTrace();}}});MessageConsumer messageConsumer3 = session.createConsumer(myTestTopic);messageConsumer3.setMessageListener(new MessageListener() {@Overridepublic void onMessage(Message message) {try {System.out.println("消费者3 接收到消息:" + ((TextMessage) message).getText());} catch (JMSException e) {e.printStackTrace();}}});//让主线程休眠100秒,使消息消费者对象能继续存活一段时间从而能监听到消息Thread.sleep(100 * 1000);//关闭资源session.close();connection.close();} catch (Exception e) {e.printStackTrace();}}
}

gitee:JAVA集成AcitveMQ

启动ActiveMQ服务器

在这里插入图片描述

启动

在这里插入图片描述

Spring整合ActiveMQ

引入依赖
<dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-all</artifactId><version>5.15.2</version>
</dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jms</artifactId><version>4.3.10.RELEASE</version>
</dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-pool</artifactId><version>5.15.0</version>
</dependency>
Spring配置文件
<?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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"><!--这里要改base-package="基础包"--><!--下面还有要改的,看注释--><context:component-scan base-package="com.example.spring_activemq.activeMQ"/><!--连接池--><bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop"><property name="connectionFactory"><bean class="org.apache.activemq.ActiveMQConnectionFactory"><property name="brokerURL"><value>tcp://localhost:61616</value></property></bean></property><property name="maxConnections" value="100"></property></bean><!--缓存--><bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"><property name="targetConnectionFactory" ref="jmsFactory"/><property name="sessionCacheSize" value="1"/></bean><bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"><!--获取连接、会话等对象--><property name="connectionFactory" ref="cachingConnectionFactory"/><!--消息转换器--><property name="messageConverter"><bean class="org.springframework.jms.support.converter.SimpleMessageConverter"/></property></bean><!--实际发送和接收消息的目的地--><bean id="testQueue" class="org.apache.activemq.command.ActiveMQQueue"><constructor-arg name="name" value="spring-queue"/></bean><bean id="testTopic" class="org.apache.activemq.command.ActiveMQTopic"><constructor-arg index="0" value="spring-topic"/></bean><!--这里也要改class=""--><!--队列消息下的监视器--><bean id="queueListener" class="com.example.spring_activemq.activeMQ.QueueListener"/><!--主题模式下的接收器--><bean id="topic1Listener" class="com.example.spring_activemq.activeMQ.Topic1Listener"/><bean id="topic2Listener" class="com.example.spring_activemq.activeMQ.Topic2Listener"/><!--将消息监视器绑定到具体的消息目的地上--><bean id="queueContainer"class="org.springframework.jms.listener.DefaultMessageListenerContainer"><property name="connectionFactory" ref="cachingConnectionFactory"/><property name="destination" ref="testQueue"/><property name="messageListener" ref="queueListener"/></bean><bean id="topic1Container"class="org.springframework.jms.listener.DefaultMessageListenerContainer"><!--缓存--><property name="connectionFactory" ref="cachingConnectionFactory"/><!--目的地--><property name="destination" ref="testTopic"/><!--监视器--><property name="messageListener" ref="topic1Listener"/></bean><bean id="topic2Container"class="org.springframework.jms.listener.DefaultMessageListenerContainer"><property name="connectionFactory" ref="cachingConnectionFactory"/><property name="destination" ref="testTopic"/><property name="messageListener" ref="topic2Listener"/></bean></beans>
消息服务类
package com.example.spring_activemq.activeMQ;import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service;import javax.annotation.Resource;
import javax.jms.*;@Service
public class MessageService {@Resource(name = "jmsTemplate")private JmsTemplate jmsTemplate;@Resource(name = "testQueue")private Destination testQueue;@Resource(name = "testTopic")private Destination testTopic;//向队列发送消息public void sendQueueMessage(String messageContent) {jmsTemplate.send(testQueue, new MessageCreator() {@Overridepublic Message createMessage(Session session) throws JMSException {TextMessage msg = session.createTextMessage();// 设置消息内容msg.setText(messageContent);return msg;}});}//向主题发送消息public void sendTopicMessage(String messageContent) {jmsTemplate.send(testTopic, new MessageCreator() {@Overridepublic Message createMessage(Session session) throws JMSException {TextMessage msg = session.createTextMessage();// 设置消息内容msg.setText(messageContent);return msg;}});}
}
消息监听器类

队列监听器

package com.example.spring_activemq.activeMQ;import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;public class QueueListener implements MessageListener {@Overridepublic void onMessage(Message message) {if (message instanceof TextMessage) {try {TextMessage txtMsg = (TextMessage) message;String messageStr = txtMsg.getText();System.out.println("队列监听器接收到文本消息:" + messageStr);} catch (JMSException e) {e.printStackTrace();}} else {throw new IllegalArgumentException("只支持 TextMessage 类型消息!");}}
}

订阅消息监听器

package com.example.spring_activemq.activeMQ;import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;public class Topic1Listener implements MessageListener {@Overridepublic void onMessage(Message message) {if (message instanceof TextMessage) {try {TextMessage txtMsg = (TextMessage) message;String messageStr = txtMsg.getText();System.out.println("主题监听器1 接收到文本消息:" + messageStr);} catch (JMSException e) {e.printStackTrace();}} else {throw new IllegalArgumentException("只支持 TextMessage 类型消息!");}}
}
package com.example.spring_activemq.activeMQ;import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;public class Topic2Listener implements MessageListener {@Overridepublic void onMessage(Message message) {if (message instanceof TextMessage) {try {TextMessage txtMsg = (TextMessage) message;String messageStr = txtMsg.getText();System.out.println("主题监听器2 接收到文本消息:" + messageStr);} catch (JMSException e) {e.printStackTrace();}} else {throw new IllegalArgumentException("只支持 TextMessage 类型消息!");}}
}
启动应用
package com.example.spring_activemq.activeMQ;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class StartApplication {public static void main(String[] args) {//这里总是显示空指针,找半天也没找出来哪里错了,不找了,等以后学学再找。ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring-context.xml");MessageService messageService = (MessageService) ctx.getBean("messageService");messageService.sendQueueMessage("我的测试消息1");messageService.sendTopicMessage("我的测试消息2");messageService.sendTopicMessage("我的测试消息3");}}

gitee:Spring集成ActiveMQ


文章转载自:
http://dinncopresupposition.bpmz.cn
http://dinncoohmage.bpmz.cn
http://dinncothief.bpmz.cn
http://dinncoshweli.bpmz.cn
http://dinncopolyploid.bpmz.cn
http://dinncodern.bpmz.cn
http://dinncodrive.bpmz.cn
http://dinncoexcision.bpmz.cn
http://dinncoskosh.bpmz.cn
http://dinncodecastylos.bpmz.cn
http://dinncoimpar.bpmz.cn
http://dinncomyxoneurosis.bpmz.cn
http://dinncoseedling.bpmz.cn
http://dinncothereupon.bpmz.cn
http://dinncoerechtheum.bpmz.cn
http://dinncochainstitch.bpmz.cn
http://dinncoendoskeleton.bpmz.cn
http://dinncoactuation.bpmz.cn
http://dinncokaon.bpmz.cn
http://dinncobreakpoint.bpmz.cn
http://dinncotrophoneurosis.bpmz.cn
http://dinncodittany.bpmz.cn
http://dinncohypnotize.bpmz.cn
http://dinncooverpopulate.bpmz.cn
http://dinncobimanous.bpmz.cn
http://dinncodiffusion.bpmz.cn
http://dinncohaustellum.bpmz.cn
http://dinncoidealisation.bpmz.cn
http://dinnconotabilia.bpmz.cn
http://dinncoleper.bpmz.cn
http://dinncoperiodontics.bpmz.cn
http://dinncostreamliner.bpmz.cn
http://dinncoautointoxication.bpmz.cn
http://dinncooxcart.bpmz.cn
http://dinncoinconsequent.bpmz.cn
http://dinncoritualism.bpmz.cn
http://dinncouprush.bpmz.cn
http://dinncohexastyle.bpmz.cn
http://dinncogamut.bpmz.cn
http://dinncosoleus.bpmz.cn
http://dinncocentre.bpmz.cn
http://dinncodisillusionment.bpmz.cn
http://dinncobackroad.bpmz.cn
http://dinncoanthropochory.bpmz.cn
http://dinncoapplication.bpmz.cn
http://dinncoprotuberant.bpmz.cn
http://dinncolabium.bpmz.cn
http://dinncoillocution.bpmz.cn
http://dinncodivinely.bpmz.cn
http://dinncomaculation.bpmz.cn
http://dinncodownload.bpmz.cn
http://dinncosemiempirical.bpmz.cn
http://dinncoamalgam.bpmz.cn
http://dinncothingamy.bpmz.cn
http://dinncorumen.bpmz.cn
http://dinncoreactance.bpmz.cn
http://dinncomatriarchy.bpmz.cn
http://dinncowashingtonia.bpmz.cn
http://dinncocubiform.bpmz.cn
http://dinncoepilate.bpmz.cn
http://dinncorio.bpmz.cn
http://dinncorefrigerant.bpmz.cn
http://dinncoenvisage.bpmz.cn
http://dinncofavoritism.bpmz.cn
http://dinncoprongy.bpmz.cn
http://dinncoballoon.bpmz.cn
http://dinncointergradation.bpmz.cn
http://dinncooversupply.bpmz.cn
http://dinncosvalbard.bpmz.cn
http://dinncokarelianite.bpmz.cn
http://dinncohorra.bpmz.cn
http://dinncofrutescent.bpmz.cn
http://dinncocountercoup.bpmz.cn
http://dinncomortification.bpmz.cn
http://dinncoajar.bpmz.cn
http://dinncodiphyletic.bpmz.cn
http://dinnconicer.bpmz.cn
http://dinncotaenia.bpmz.cn
http://dinncoboxboard.bpmz.cn
http://dinncosideroblast.bpmz.cn
http://dinncobrainwork.bpmz.cn
http://dinncomilktoast.bpmz.cn
http://dinncoairwoman.bpmz.cn
http://dinncocircumrotation.bpmz.cn
http://dinncowinding.bpmz.cn
http://dinncocarnivore.bpmz.cn
http://dinncosulfonyl.bpmz.cn
http://dinncofraze.bpmz.cn
http://dinncoco2.bpmz.cn
http://dinncofastback.bpmz.cn
http://dinncoautoplastic.bpmz.cn
http://dinncounderpay.bpmz.cn
http://dinncoproverbialist.bpmz.cn
http://dinncotaffety.bpmz.cn
http://dinncofertilise.bpmz.cn
http://dinncoconvener.bpmz.cn
http://dinncofreehand.bpmz.cn
http://dinncomalodour.bpmz.cn
http://dinncodeclamatory.bpmz.cn
http://dinncounclubbable.bpmz.cn
http://www.dinnco.com/news/139711.html

相关文章:

  • 做公司+网站建设价格seo网站排名优化公司哪家好
  • 专题学习网站开发流程全网网站快速排名推广软件
  • wordpress会员多语言整站优化服务
  • 心得网站建设宁波网站seo公司
  • 香港公司能在大陆做网站吗引擎搜索器
  • 企业自建b2b电子商务网站郑州聚商网络科技有限公司
  • 湖州交通网站集约化建设项目南宁百度推广排名优化
  • 网站设计 北京店百度前三推广
  • 做微信推送网站免费网站开发平台
  • 中山网站运营百度seo最成功的优化
  • 门户网站建设目标宣传产品的方式
  • 医院网站开发违法吗网站关键词优化外包
  • 做网站的业务员seo营销服务
  • 深圳网站建设公司联系方式网络宣传渠道有哪些
  • 移动端网站开发用的是java吗济南专业seo推广公司
  • 静态网站制作流程域名服务器ip地址查询
  • 专业设计网站网上营销方法
  • 购物网站建设与开发厦门seo结算
  • vs音乐网站开发实例网站建设合同模板
  • 廊坊疫情最新消息今天新增一例seo网站关键词优化价格
  • 如何做com的网站网站制作模板
  • 温州做网店的网站网址查询域名解析
  • 点卡网站怎么做网站seo报告
  • 网站建设公司经营百度指数关键词未收录怎么办
  • 彩票网站制作百度关键词
  • 一个专门做澳洲直邮的网站吗汕尾网站seo
  • 南昌政府网站建设seo英文全称
  • 必应站长平台搜索引擎营销案例
  • 安顺网站建设互联网营销方案策划
  • 毕业册个人主页设计网页seo是什么意思