activeMQ在WINDOWS上部署和测试

activeMQ在WINDOWS上部署和测试

ActiveMQ一直都没有用过。今天也只是大致部署了一些,很多东西还是没有懂。
下载地址:
http://activemq.apache.org/
基本上没有怎么修改配置,放置在D:\tool\apache-activemq-4.1.1
直接运行了BIN下面的BAT就启动了服务。

然后用MULE的MuleClient来连接进行了一下测试:
发送的类ClientToolSend.java:
package com.megaeyes.jms;

import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOException;

import com.megaeyes.sms.gateway.databean.MessageBean;

public class ClientToolSend {

public static void main(String[] args) {
   MuleClient client = null;
   try {
    client = new MuleClient();
    client.setProperty("jms.connectionFactoryJndiName",
      "ConnectionFactory");
    client.setProperty("jms.jndiInitialFactory",
      "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    client.setProperty("jms.specification", "1.1");
    client.setProperty("jms.jndiProviderUrl", "tcp://localhost:61616");

    MessageBean message = new MessageBean();
    message.setDeviceIP("192.168.1.1");
    message.setDeviceName("sillycat");
    message.setDeviceTypeName("localhost");
    client.send("jms://ConnectionFactory", message, null);

    System.out.println("=========send success============");
    client.dispose();
   } catch (UMOException e) {
    e.printStackTrace();
   }
}

}


接受的类ClientToolReceive.java:
package com.megaeyes.jms;

import org.mule.extras.client.MuleClient;
import org.mule.umo.UMOException;
import org.mule.umo.UMOMessage;

import com.megaeyes.sms.gateway.databean.MessageBean;

public class ClientToolReceive {

public static void main(String[] args) {
   MuleClient client = null;
   try {
    client = new MuleClient();
    client.setProperty("jms.connectionFactoryJndiName",
      "ConnectionFactory");
    client.setProperty("jms.jndiInitialFactory",
      "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
    client.setProperty("jms.specification", "1.1");
    client.setProperty("jms.jndiProviderUrl", "tcp://localhost:61616");

    for (int i = 0; i < 3; i++) {
     UMOMessage result = client.receive("jms://ConnectionFactory",
       -1);
     if (result != null) {
      Object o = result.getPayload();
      System.out.println("========receive UMOMessage: " + o);
      MessageBean message = null;
      if (o instanceof MessageBean) {
       message = (MessageBean) o;
      }
      System.out.println("==========receive DeviceIP :"
        + message.getDeviceIP());
      System.out.println("==========receive DeviceName :"
        + message.getDeviceName());
     } else {
      System.out.println("========no UMOMessage=========");
     }
    }
    client.dispose();
   } catch (UMOException e) {
    e.printStackTrace();
   }
}

}

你可能感兴趣的:(apache,windows,activemq,jms)