本文整理汇总了Java中org.apache.activemq.ActiveMQConnection.DEFAULT_PASSWORD属性的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQConnection.DEFAULT_PASSWORD属性的具体用法?Java ActiveMQConnection.DEFAULT_PASSWORD怎么用?Java ActiveMQConnection.DEFAULT_PASSWORD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.activemq.ActiveMQConnection
的用法示例。
在下文中一共展示了ActiveMQConnection.DEFAULT_PASSWORD属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Sender
/**
*
* @param queue_name : name of destination message queue
* @param host_name : destination ip/host name
*/
public Sender(String queue_name, String host_name) {
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://" + host_name +":61616");
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queue_name);
producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
} catch (JMSException je) {
je.printStackTrace();
}
}
示例2: Receiver
public Receiver(String queue_name) {
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(Boolean.FALSE,
Session.AUTO_ACKNOWLEDGE);
destination = session.createQueue(queue_name);
consumer = session.createConsumer(destination);
} catch(JMSException je) {
je.printStackTrace();
}
}
示例3: init
@Override
public void init(Config config) throws TestException {
super.init(config);
String providerUrl = config.getPropertyValue("providerUrl");
String destinationType = config.getPropertyValue("destinationType");
String destinationName = config.getPropertyValue("destinationName");
if (providerUrl == null) {
throw new TestException("providerUrl property must be specified");
}
if (destinationType == null) {
throw new TestException("destinationType property must be specified");
}
if (!(destinationType.equals("Queue") || destinationType.equals("Topic"))) {
throw new TestException("destinationType property must be 'Queue' or 'Topic'");
}
if (destinationName == null) {
throw new TestException("destinationName property must be specified");
}
try {
String userName = ActiveMQConnection.DEFAULT_USER;
String password = ActiveMQConnection.DEFAULT_PASSWORD;
String tuning = "?tcpNoDelay=true&socketBufferSize=65536&wireFormat.tcpNoDelayEnabled=true&wireFormat.cacheEnabled=true&wireFormat.cacheSize=1024&wireFormat.tightEncodingEnabled=true";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(userName, password, providerUrl + tuning);
connection = factory.createConnection();
connection.start();
boolean transacted = false;
session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
Destination destination = (destinationType.equals("Queue")) ? session.createQueue(destinationName) : session.createTopic(destinationName);
producer = session.createProducer(destination);
} catch (JMSException error) {
throw new TestException(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()), error);
}
}
示例4: init
@Override
public void init(Config config) throws TestException {
super.init(config);
String providerUrl = config.getPropertyValue("providerUrl");
String destinationType = config.getPropertyValue("destinationType");
String destinationName = config.getPropertyValue("destinationName");
if (providerUrl == null) {
throw new TestException("providerUrl property must be specified");
}
if (destinationType == null) {
throw new TestException("destinationType property must be specified");
}
if (!(destinationType.equals("Queue") || destinationType.equals("Topic"))) {
throw new TestException("destinationType property must be 'Queue' or 'Topic'");
}
if (destinationName == null) {
throw new TestException("destinationName property must be specified");
}
try {
String userName = ActiveMQConnection.DEFAULT_USER;
String password = ActiveMQConnection.DEFAULT_PASSWORD;
String tuning = "?tcpNoDelay=true&socketBufferSize=65536&wireFormat.tcpNoDelayEnabled=true&wireFormat.cacheEnabled=true&wireFormat.cacheSize=1024&wireFormat.tightEncodingEnabled=true";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
userName, password, providerUrl + tuning);
connection = factory.createConnection();
connection.start();
boolean transacted = false;
session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
Destination destination = (destinationType.equals("Queue")) ? session.createQueue(destinationName) : session.createTopic(destinationName);
consumer = session.createConsumer(destination);
} catch (JMSException error) {
throw new TestException(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()), error);
}
}
示例5: main
public static void main(String[] args) throws JMSException {
// 通过username,password,url创建连接工厂接口
ConnectionFactory factory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
// 通过连接工厂创建一个新的连接接口
Connection connection = factory.createConnection();
// 通过连接接口创建一个会话接口
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// 会话接口创建有关主题的目标接口
Destination destination = session.createQueue("queue_test");
// 会话接口再根据目标接口来创建一个消息生产者接口
MessageProducer producer = session.createProducer(destination);
//设置消息生存时间,超过该时间,消息会被移除,不设置永久
// producer.setTimeToLive(60000);
//设置消息优先级0~9个级别,0最低,9最高
producer.setPriority(5);
//设置消息持久性:DeliveryMode.PERSISTENT,DeliveryMode.NON_PERSISTENT,默认为PERSISTENT
//持久性消息只被传输一次,非持久性消息最多被传输一次,有可能是0次,比如,JMS提供者故障时消息被丢失的时候
//可以分别测试设置PERSISTENT和NON_PERSISTENT,当关闭JMS重新启动
// producer.setDeliveryMode(DeliveryMode.PERSISTENT);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 调用会话生成一个文本消息
Message message = session.createTextMessage("Hello World!");
//设置消息选择器,当有多个应用都需要从同一个队列取消息的时候,可以通过指定消息选择器,来进行消息过滤
//消息头中的可以使用选择器的属性:JMSDeliveryMode、JMSPriority、JMSMessageID、JMSTimestamp、JMSCorrelationID、JMSType
//这里使用JMSCorrelationID来指定消息选择器,消息的接收者在创建的时候需要指定
//MessageConsumer consumer = session.createConsumer(dest, "JMSMessageID ='123456789'");
//使用producer.setDeliveryMode
// message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
//设置消息优先级0~9个级别,0最低,9最高,如果设置了producer.setPriority,则优先级以producer设置的为准
message.setJMSPriority(4);
//设置消息时间戳
message.setJMSTimestamp(System.currentTimeMillis());
//设置消息过期时间,如果设置为0标示永不过期,使用上面的方法:producer.setTimeToLive
// message.setJMSExpiration(5);
//设置消息类型
message.setJMSType("TEST");
//设置消息惟一标识,只能在消息发送后才能确定
//message.setJMSMessageID("123456789");
//设置消息返回时发送给指定目标Destination
message.setJMSReplyTo(session.createQueue("queue_test_replay"));
// 通过生产者接口Send将消息发布到ActiveMQ服务器
producer.send(message);
//消息发送后获取的JMSMessageID和自己指定的不一样,这是自动生成的
System.out.println(message.getJMSMessageID());
// 关闭会话
session.close();
// 关闭连接
connection.close();
}
示例6: main
public static void main(String[] args) throws JMSException {
// 通过username,password,url创建连接工厂接口
ConnectionFactory factory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
// 通过连接工厂创建一个新的连接接口
Connection connection = factory.createConnection();
connection.start();
// 通过连接接口创建一个会话接口
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// 会话接口创建有关主题的目标接口
Destination destination = session.createQueue("queue_test_replay");
// 会话接口再根据目标接口来创建一个消息消费者接口
MessageConsumer consumer = session.createConsumer(destination);
//指定消息选择器,只接收指定选择器的消息,表达式符合SQL语法,发送消息的时候需要设置选择器值
// MessageConsumer consumer = session.createConsumer(destination, "JMSCorrelationID ='123456789'");
//同步接收消息:只能接收一次消息
// 1.阻塞等待消息,直到收到信息才返回
// TextMessage message = (TextMessage) consumer.receive();
// 2.阻塞等待消息,超出指定超时时间或收到信息就不等待
// TextMessage message = (TextMessage) consumer.receive(3000);
// 3. 不阻塞等待消息,有消息直接返回,无消息返回null
// TextMessage message = (TextMessage) consumer.receiveNoWait();
// if (null != message) {
// System.out.println("收到消息:" + message.getText());
// Destination replyDdestination = message.getJMSReplyTo();
// //创建一个新的MessageProducer来发送一个回复消息。
// MessageProducer producer = session.createProducer(replyDdestination);
// producer.send(session.createTextMessage("Hello " + message.getText()));
//
// } else {
// System.out.println("没有收到消息!");
// }
//
//异步消息,使用监听器来接收消息,当有消息的时候,会自动调用onMessage方法,可以多次接收消息,确保Session不要关闭
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
// 消息消费者接收消息
if (null != message) {
try {
System.out.println("收到replay消息:" + ((TextMessage) message).getText());
} catch (JMSException e) {
e.printStackTrace();
}
} else {
System.out.println("没有收到消息!");
}
}
});
// 关闭会话,设置监听消息的时候不要关闭
// session.close();
// 关闭连接,设置监听消息的时候不要关闭
// connection.close();
}
示例7: main
public static void main(String[] args) throws JMSException {
// 通过username,password,url创建连接工厂接口
ConnectionFactory factory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
// 通过连接工厂创建一个新的连接接口
Connection connection = factory.createConnection();
connection.start();
// 通过连接接口创建一个会话接口
final Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// 会话接口创建有关主题的目标接口
Destination destination = session.createQueue("queue_test");
// Destination destination = session.createQueue("queue_test_replay");
// 会话接口再根据目标接口来创建一个消息消费者接口
MessageConsumer consumer = session.createConsumer(destination);
//指定消息选择器,只接收指定选择器的消息,表达式符合SQL语法,发送消息的时候需要设置选择器值
// MessageConsumer consumer = session.createConsumer(destination, "JMSCorrelationID ='123456789'");
//同步接收消息:只能接收一次消息
// 1.阻塞等待消息,直到收到信息才返回
// TextMessage message = (TextMessage) consumer.receive();
// 2.阻塞等待消息,超出指定超时时间或收到信息就不等待
// TextMessage message = (TextMessage) consumer.receive(3000);
// 3. 不阻塞等待消息,有消息直接返回,无消息返回null
// TextMessage message = (TextMessage) consumer.receiveNoWait();
// if (null != message) {
// System.out.println("收到消息:" + message.getText());
// } else {
// System.out.println("没有收到消息!");
// }
//异步消息,使用监听器来接收消息,当有消息的时候,会自动调用onMessage方法,可以多次接收消息,确保Session不要关闭
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
// 消息消费者接收消息
if (null != message) {
try {
String msg = ((TextMessage) message).getText();
System.out.println("收到消息:" + msg);
//根据JMSReplyTo获取返回Destination
Destination replyDdestination = message.getJMSReplyTo();
//创建一个新的MessageProducer来发送一个回复消息。
MessageProducer producer = session.createProducer(replyDdestination);
producer.send(session.createTextMessage("Hello " + msg));
} catch (JMSException e) {
e.printStackTrace();
}
} else {
System.out.println("没有收到消息!");
}
}
});
// 关闭会话,设置监听消息的时候不要关闭
// session.close();
// 关闭连接,设置监听消息的时候不要关闭
// connection.close();
}
示例8: main
public static void main(String[] args) {
// ConnectionFactory :连接工厂,JMS 用它创建连接
ConnectionFactory connectionFactory;
// Connection :JMS 客户端到JMS Provider 的连接
Connection connection = null;
// Session: 一个发送或接收消息的线程
Session session;
// Destination :消息的目的地;消息发送给谁.
Destination destination;
// MessageProducer:消息发送者
MessageProducer producer;
// TextMessage message;
// 构造ConnectionFactory实例对象,此处采用ActiveMq的实现jar
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
destination = session.createQueue("queue1");
// 得到消息生成者【发送者】
producer = session.createProducer(destination);
// 设置不持久化,此处学习,实际根据项目决定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 构造消息,此处写死,项目就是参数,或者方法获取
sendMessage(session, producer);
session.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例9: main
public static void main(String[] args) {
// ConnectionFactory :连接工厂,JMS 用它创建连接
ConnectionFactory connectionFactory;
// Connection :JMS 客户端到JMS Provider 的连接
Connection connection = null;
// Session: 一个发送或接收消息的线程
Session session;
// Destination :消息的目的地;消息发送给谁.
Destination destination;
// 消费者,消息接收者
MessageConsumer consumer;
connectionFactory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://localhost:61616");
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
destination = session.createQueue("queue1");
consumer = session.createConsumer(destination);
while (true) {
// 设置接收者接收消息的时间,为了便于测试,这里谁定为100s
TextMessage message = (TextMessage) consumer.receive(100000);
if (null != message) {
System.out.println("收到消息" + message.getText());
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例10: main
public static void main(String[] args) {
// ConnectionFactory :连接工厂,JMS 用它创建连接
ConnectionFactory connectionFactory;
// Connection :JMS 客户端到JMS Provider 的连接
Connection connection = null;
// Session: 一个发送或接收消息的线程
Session session;
// Destination :消息的目的地;消息发送给谁.
Destination destination;
// MessageProducer:消息发送者
MessageProducer producer;
// TextMessage message;
// 构造ConnectionFactory实例对象,此处采用ActiveMq的实现jar
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
// 得到消息生成者【发送者】
producer = session.createProducer(destination);
// 设置不持久化,此处学习,实际根据项目决定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 构造消息,此处写死,项目就是参数,或者方法获取
sendMessage(session, producer);
session.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例11: main
public static void main(String[] args) {
// ConnectionFactory :连接工厂,JMS 用它创建连接
ConnectionFactory connectionFactory;
// Connection :JMS 客户端到JMS Provider 的连接
Connection connection = null;
// Session: 一个发送或接收消息的线程
Session session;
// Destination :消息的目的地;消息发送给谁.
Destination destination;
// 消费者,消息接收者
MessageConsumer consumer;
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.FALSE,
Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
consumer = session.createConsumer(destination);
while (true) {
//设置接收者接收消息的时间,为了便于测试,这里谁定为100s
TextMessage message = (TextMessage) consumer.receive(100000);
if (null != message) {
System.out.println("收到消息" + message.getText());
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例12: main
public static void main(String[] args) {
// ConnectionFactory :连接工厂,JMS 用它创建连接
ConnectionFactory connectionFactory;
// Connection :JMS 客户端到JMS Provider 的连接
Connection connection = null;
// Session: 一个发送或接收消息的线程
Session session;
// Destination :消息的目的地;消息发送给谁.
Destination destination;
// MessageProducer:消息发送者
MessageProducer producer;
// TextMessage message;
// 构造ConnectionFactory实例对象,此处采用ActiveMq的实现jar
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.TRUE,
Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
// 得到消息生成者【发送者】
producer = session.createProducer(destination);
// 设置不持久化,此处学习,实际根据项目决定
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 构造消息,此处写死,项目就是参数,或者方法获取
sendMessage(session, producer);
session.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}
示例13: main
public static void main(String[] args) {
// ConnectionFactory :连接工厂,JMS 用它创建连接
ConnectionFactory connectionFactory;
// Connection :JMS 客户端到JMS Provider 的连接
Connection connection = null;
// Session: 一个发送或接收消息的线程
Session session;
// Destination :消息的目的地;消息发送给谁.
Destination destination;
// 消费者,消息接收者
MessageConsumer consumer;
connectionFactory = new ActiveMQConnectionFactory(
ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://localhost:61616");
try {
// 构造从工厂得到连接对象
connection = connectionFactory.createConnection();
// 启动
connection.start();
// 获取操作连接
session = connection.createSession(Boolean.FALSE,
Session.AUTO_ACKNOWLEDGE);
// 获取session注意参数值xingbo.xu-queue是一个服务器的queue,须在在ActiveMq的console配置
destination = session.createQueue("FirstQueue");
consumer = session.createConsumer(destination);
while (true) {
//设置接收者接收消息的时间,为了便于测试,这里谁定为100s
TextMessage message = (TextMessage) consumer.receive(100000);
if (null != message) {
System.out.println("收到消息" + message.getText());
} else {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != connection)
connection.close();
} catch (Throwable ignore) {
}
}
}