JMS之ActiveMQ Linux下安装与应用实例

JMS之ActiveMQ Linux下安装与应用实例

1.下载activeMQ安装包,拷贝到/activeMQ目录下

apache-activemq-5.10.0-bin.tar.gz,下载地址

2.解压文件到运行目录

[root@linuxidc softs]# tar -xzvf /server/apache-activemq-5.10.0-bin.tar.gz

3.为了方便管理,重命名

[root@linuxidc softs]# mv apache-activemq-5.10.0 activemq-5.10.0

[root@linuxidc softs]# cd activemq-5.10.0/
[root@linuxidc activemq-5.10.0]# ll
total 6304
-rwxr-xr-x 1 root root 6371237 Jun  5  2014 activemq-all-5.10.0.jar
drwxr-xr-x 5 root root    4096 Jan 11 23:31 bin
drwxr-xr-x 2 root root    4096 Jan 11 23:31 conf
drwxr-xr-x 2 root root    4096 Jan 11 23:31 data
drwxr-xr-x 2 root root    4096 Jan 11 23:31 docs
drwxr-xr-x 8 root root    4096 Jan 11 23:31 examples
drwxr-xr-x 6 root root    4096 Jan 11 23:31 lib
-rw-r--r-- 1 root root  40580 Jun  5  2014 LICENSE
-rw-r--r-- 1 root root    3334 Jun  5  2014 NOTICE
-rw-r--r-- 1 root root    2610 Jun  5  2014 README.txt
drwxr-xr-x 7 root root    4096 Jan 11 23:31 webapps
drwxr-xr-x 3 root root    4096 Jan 11 23:31 webapps-demo
[root@linuxidc activemq-5.10.0]# cd bin/
[root@linuxidc bin]# ll
total 152
-rwxr-xr-x 1 root root 22126 Jun  5  2014 activemq
-rwxr-xr-x 1 root root  5665 Jun  5  2014 activemq-admin
-rw-r--r-- 1 root root 15954 Jun  5  2014 activemq.jar
-rwxr-xr-x 1 root root  6189 Jun  5  2014 diag
drwxr-xr-x 2 root root  4096 Jan 11 23:31 linux-x86-32
drwxr-xr-x 2 root root  4096 Jan 11 23:31 linux-x86-64
drwxr-xr-x 2 root root  4096 Jan 11 23:31 macosx
-rwxr-xr-x 1 root root 83820 Jun  5  2014 wrapper.jar

4.启动服务

[root@linuxidc bin]# ./activemq start
INFO: Using default configuration
(you can configure options in one of these file: /etc/default/activemq /root/.activemqrc)

INFO: Invoke the following command to create a configuration file
./activemq setup [ /etc/default/activemq | /root/.activemqrc ]

INFO: Using Java '/softs/jdk1.6.0_30/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : '/softs/activemq-5.10.0/data/activemq-linuxidc.pid' (pid '28962')

5.查看是否启动成功

[root@linuxidc bin]#
[root@linuxidc bin]# ps -ef | grep activemq
root    28962    1 32 23:32 pts/0    00:00:04 /softs/jdk1.6.0_30/bin/java -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/softs/activemq-5.10.0/conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headless=true -Djava.io.tmpdir=/softs/activemq-5.10.0/tmp -Dactivemq.classpath=/softs/activemq-5.10.0/conf; -Dactivemq.home=/softs/activemq-5.10.0 -Dactivemq.base=/softs/activemq-5.10.0 -Dactivemq.conf=/softs/activemq-5.10.0/conf -Dactivemq.data=/softs/activemq-5.10.0/data -jar /softs/activemq-5.10.0/bin/activemq.jar start
root    29011 28898  0 23:32 pts/0    00:00:00 grep activemq
[root@linuxidc bin]#
[root@linuxidc bin]#

6.停止服务

[root@linuxidc data]#
[root@linuxidc data]# kill 28962
[root@linuxidc data]#
[root@linuxidc data]# ps -ef | grep activemq
root    29078 28898  0 23:42 pts/0    00:00:00 grep activemq
[root@linuxidc data]#

到此环境准备成功

demo应用

package com.wzh.activemq;

import java.io.Serializable;

public class User implements Serializable{

private static final long serialVersionUID = 1L;

private String username ;
 
 private String password ;
 
 public User(String username,String password){
  this.username = username ;
  this.password = password ;
 }

public String getUsername() {
  return username;
 }

public void setUsername(String username) {
  this.username = username;
 }

public String getPassword() {
  return password;
 }

public void setPassword(String password) {
  this.password = password;
 }

@Override
 public String toString() {
  // TODO Auto-generated method stub
  return "[username="+username+",password="+password+"]" ;
 }

}

点对点:
生产者:

package com.wzh.activemq;

import java.io.Serializable;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

public class P2PMessageProducer {

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/16021.html