本文整理汇总了Java中org.apache.activemq.ActiveMQConnection.close方法的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQConnection.close方法的具体用法?Java ActiveMQConnection.close怎么用?Java ActiveMQConnection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.activemq.ActiveMQConnection
的用法示例。
在下文中一共展示了ActiveMQConnection.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTestStreamMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void sendTestStreamMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
StreamMessage streamMessage = session.createStreamMessage();
streamMessage.writeBoolean(true);
streamMessage.writeByte((byte) 10);
streamMessage.writeBytes(TEXT.getBytes());
streamMessage.writeChar('A');
streamMessage.writeDouble(55.3D);
streamMessage.writeFloat(79.1F);
streamMessage.writeInt(37);
streamMessage.writeLong(56652L);
streamMessage.writeObject(new String("VVVV"));
streamMessage.writeShort((short) 333);
streamMessage.writeString(TEXT);
producer.send(streamMessage);
connection.close();
}
示例2: sendTestMapMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void sendTestMapMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
MapMessage mapMessage = session.createMapMessage();
mapMessage.setBoolean("boolean-type", true);
mapMessage.setByte("byte-type", (byte) 10);
mapMessage.setBytes("bytes-type", TEXT.getBytes());
mapMessage.setChar("char-type", 'A');
mapMessage.setDouble("double-type", 55.3D);
mapMessage.setFloat("float-type", 79.1F);
mapMessage.setInt("int-type", 37);
mapMessage.setLong("long-type", 56652L);
mapMessage.setObject("object-type", new String("VVVV"));
mapMessage.setShort("short-type", (short) 333);
mapMessage.setString("string-type", TEXT);
producer.send(mapMessage);
connection.close();
}
示例3: closeConnection
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
static void closeConnection(Session session, ActiveMQConnection connection) {
try {
session.close();
connection.close();
} catch (JMSException ex) {
throw new MessageQueueException("Could not close session connection", ex);
}
}
示例4: receiveTestMapMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQMapMessage receiveTestMapMessage(ActiveMQConnectionFactory factory) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue);
ActiveMQMapMessage rc = (ActiveMQMapMessage) consumer.receive();
connection.close();
return rc;
}
示例5: testTempQueueDelete
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@Test
public void testTempQueueDelete() throws Exception {
connection.start();
QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = queueSession.createTemporaryQueue();
ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
try {
QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = newQueueSession.createSender(tempQueue);
Message msg = queueSession.createMessage();
queueSender.send(msg);
try {
QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
fail("should have gotten exception but got consumer: " + consumer);
} catch (JMSException ex) {
//correct
}
connection.close();
try {
Message newMsg = newQueueSession.createMessage();
queueSender.send(newMsg);
} catch (JMSException e) {
//ok
}
} finally {
newConn.close();
}
}
示例6: sendTestMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void sendTestMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage(message));
connection.close();
}
示例7: receiveTestStreamMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQStreamMessage receiveTestStreamMessage(ActiveMQConnectionFactory factory) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue);
ActiveMQStreamMessage rc = (ActiveMQStreamMessage) consumer.receive();
connection.close();
return rc;
}
示例8: testDurableSubRedeliveryFlagAfterRestartNotSupported
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@org.junit.Test
public void testDurableSubRedeliveryFlagAfterRestartNotSupported() throws Exception {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("failover:(" + broker.getTransportConnectors().get(0).getPublishableConnectString() + ")?jms.prefetchPolicy.all=0");
connection = (ActiveMQConnection) connectionFactory.createConnection();
connection.setClientID("id");
connection.start();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
ActiveMQTopic destination = new ActiveMQTopic(queueName);
TopicSubscriber durableSub = session.createDurableSubscriber(destination, "id");
populateDestination(10, destination, connection);
TextMessage msg = null;
for (int i = 0; i < 5; i++) {
msg = (TextMessage) durableSub.receive(20000);
LOG.info("not redelivered? got: " + msg);
assertNotNull("got the message", msg);
assertEquals("first delivery", 1, msg.getLongProperty("JMSXDeliveryCount"));
assertEquals("not a redelivery", false, msg.getJMSRedelivered());
}
durableSub.close();
restartBroker();
// make failover aware of the restarted auto assigned port
connection.getTransport().narrow(FailoverTransport.class).add(true, broker.getTransportConnectors().get(0).getPublishableConnectString());
durableSub = session.createDurableSubscriber(destination, "id");
for (int i = 0; i < 10; i++) {
msg = (TextMessage) durableSub.receive(4000);
LOG.info("redelivered? got: " + msg);
assertNotNull("got the message again", msg);
assertEquals("no reDelivery flag", false, msg.getJMSRedelivered());
msg.acknowledge();
}
connection.close();
}
示例9: receiveTestBytesMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQBytesMessage receiveTestBytesMessage(ActiveMQConnectionFactory factory) throws JMSException, UnsupportedEncodingException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue);
ActiveMQBytesMessage rc = (ActiveMQBytesMessage) consumer.receive();
connection.close();
return rc;
}
示例10: receiveTestMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQTextMessage receiveTestMessage(ActiveMQConnectionFactory factory) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue);
ActiveMQTextMessage rc = (ActiveMQTextMessage) consumer.receive();
connection.close();
return rc;
}
示例11: receiveMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private Message receiveMessage(ActiveMQConnectionFactory cf, Queue destination) throws Exception {
final ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
connection.start();
final Session consumerSession = connection.createSession(true, Session.SESSION_TRANSACTED);
final MessageConsumer consumer = consumerSession.createConsumer(destination);
Message msg = consumer.receive(5000);
consumerSession.commit();
connection.close();
return msg;
}
示例12: tearDown
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@After
public void tearDown() throws Exception {
for (ActiveMQConnection conn : connections) {
conn.close();
}
server0.stop();
server1.stop();
}
示例13: sendTestObjectMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private void sendTestObjectMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(TEXT);
producer.send(objectMessage);
connection.close();
}
示例14: receiveTestObjectMessage
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
private ActiveMQObjectMessage receiveTestObjectMessage(ActiveMQConnectionFactory factory) throws JMSException {
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(queue);
ActiveMQObjectMessage rc = (ActiveMQObjectMessage) consumer.receive();
connection.close();
return rc;
}
示例15: testPrefetch1MessageNotDispatched
import org.apache.activemq.ActiveMQConnection; //导入方法依赖的package包/类
@Test
public void testPrefetch1MessageNotDispatched() throws Exception {
// Set prefetch to 1
connection.getPrefetchPolicy().setAll(1);
connection.start();
Session session = connection.createSession(true, 0);
ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
MessageConsumer consumer = session.createConsumer(destination);
// Send 2 messages to the destination.
sendMessages(session, destination, 2);
session.commit();
// The prefetch should fill up with 1 message.
// Since prefetch is still full, the 2nd message should get dispatched
// to another consumer.. lets create the 2nd consumer test that it does
// make sure it does.
ActiveMQConnection connection2 = (ActiveMQConnection) factory.createConnection();
connection2.start();
Session session2 = connection2.createSession(true, 0);
MessageConsumer consumer2 = session2.createConsumer(destination);
System.out.println("consumer receiving ...");
// Pick up the first message.
Message message1 = consumer.receive(1000);
System.out.println("received1: " + message1);
assertNotNull(message1);
System.out.println("consumer 2 receiving...");
// Pick up the 2nd messages.
Message message2 = consumer2.receive(5000);
System.out.println("received2: " + message2);
assertNotNull(message2);
System.out.println("committing sessions !! " + session.getClass().getName());
session.commit();
System.out.println("committed session, now 2");
session2.commit();
System.out.println("all committed");
Message m = consumer.receiveNoWait();
System.out.println("received 3: " + m);
assertNull(m);
try {
connection2.close();
} catch (Throwable e) {
System.err.println("exception e: " + e);
e.printStackTrace();
}
System.out.println("Test finished!!");
}