本文整理了Java中javax.jms.Connection.start()
方法的一些代码示例,展示了Connection.start()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.start()
方法的具体详情如下:
包路径:javax.jms.Connection
类名称:Connection
方法名:start
[英]Starts (or restarts) a connection's delivery of incoming messages. A call to start on a connection that has already been started is ignored.
[中]启动(或重新启动)连接传入消息的传递。对已启动的连接的启动调用将被忽略。
代码示例来源:origin: apache/storm
protected void prepare() {
if (this.options.jmsProvider == null || this.options.msgProducer == null) {
throw new IllegalStateException("JMS Provider and MessageProducer not set.");
}
LOG.debug("Connecting JMS..");
try {
ConnectionFactory cf = this.options.jmsProvider.connectionFactory();
Destination dest = this.options.jmsProvider.destination();
this.connection = cf.createConnection();
this.session = connection.createSession(this.options.jmsTransactional,
this.options.jmsAcknowledgeMode);
this.messageProducer = session.createProducer(dest);
connection.start();
} catch (Exception e) {
LOG.warn("Error creating JMS connection.", e);
}
}
代码示例来源:origin: apache/storm
Destination dest = jmsProvider.destination();
this.connection = cf.createConnection();
this.session = connection.createSession(false, jmsAcknowledgeMode);
MessageConsumer consumer = session.createConsumer(dest);
consumer.setMessageListener(this);
this.connection.start();
代码示例来源:origin: spring-projects/spring-framework
/**
* A variant of {@link #execute(SessionCallback, boolean)} that explicitly
* creates a non-transactional {@link Session}. The given {@link SessionCallback}
* does not participate in an existing transaction.
*/
@Nullable
private <T> T executeLocal(SessionCallback<T> action, boolean startConnection) throws JmsException {
Assert.notNull(action, "Callback object must not be null");
Connection con = null;
Session session = null;
try {
con = createConnection();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
if (startConnection) {
con.start();
}
if (logger.isDebugEnabled()) {
logger.debug("Executing callback on JMS Session: " + session);
}
return action.doInJms(session);
}
catch (JMSException ex) {
throw convertJmsAccessException(ex);
}
finally {
JmsUtils.closeSession(session);
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), startConnection);
}
}
代码示例来源:origin: kiegroup/jbpm
public List<Message> receive(Queue queue) throws Exception {
List<Message> messages = new ArrayList<Message>();
Connection qconnetion = factory.createConnection();
Session qsession = qconnetion.createSession(true, QueueSession.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = qsession.createConsumer(queue);
qconnetion.start();
Message m = null;
while ((m = consumer.receiveNoWait()) != null) {
messages.add(m);
}
consumer.close();
qsession.close();
qconnetion.close();
return messages;
}
}
代码示例来源:origin: spring-projects/spring-framework
TemporaryQueue replyDestination = mock(TemporaryQueue.class);
MessageProducer messageProducer = mock(MessageProducer.class);
given(localSession.createProducer(this.queue)).willReturn(messageProducer);
given(localSession.createTemporaryQueue()).willReturn(replyDestination);
given(localSession.createConsumer(replyDestination)).willReturn(messageConsumer);
given(messageConsumer.receive()).willReturn(reply);
given(messageConsumer.receive(timeout)).willReturn(reply);
verify(this.connection).start();
verify(this.connection).close();
verify(localSession).close();
verify(messageConsumer).close();
代码示例来源:origin: spring-projects/spring-framework
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
given(txSession.getTransacted()).willReturn(true);
given(con.createSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.getTransacted();
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
con1.start();
Connection con2 = scf.createConnection();
Session session2 = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session2.commit();
session2.close();
con2.start();
con1.close();
con2.close();
verify(txSession).close();
verify(nonTxSession).close();
verify(con).start();
verify(con).stop();
verify(con).close();
代码示例来源:origin: apache/activemq-artemis
private void checkDestination(String name) throws Exception {
ConnectionFactory cf = (ConnectionFactory) namingContext.lookup("/someCF");
Connection conn = cf.createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination dest = (Destination) namingContext.lookup(name);
conn.start();
MessageConsumer cons = sess.createConsumer(dest);
MessageProducer prod = sess.createProducer(dest);
prod.send(sess.createMessage());
assertNotNull(cons.receiveNoWait());
conn.close();
}
代码示例来源:origin: apache/storm
connection = cf.createConnection();
session = messageHandler.createSession(connection);
consumer = session.createConsumer(dest);
connection.start();
} catch (Exception e) {
LOG.warn("Error creating JMS connection.", e);
代码示例来源:origin: kiegroup/jbpm
void receiveAndProcess(Queue queue, EntityManagerFactory entityManagerFactory, long waitTime, int countDown) throws Exception {
Session qsession = qconnetion.createSession(true, QueueSession.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = qsession.createConsumer(queue);
qconnetion.start();
qconnetion.close();
代码示例来源:origin: apache/flume
connection.setClientID(clientId.get());
connection.start();
} catch (JMSException e) {
throw new FlumeException("Could not create connection to broker", e);
session = connection.createSession(true, Session.SESSION_TRANSACTED);
} catch (JMSException e) {
throw new FlumeException("Could not create session", e);
messageSelector.isEmpty() ? null : messageSelector, true);
} else {
messageConsumer = session.createConsumer(destination,
messageSelector.isEmpty() ? null : messageSelector);
代码示例来源:origin: spring-projects/spring-framework
given(this.session.createConsumer(this.queue,
messageSelector ? selectorString : null)).willReturn(messageConsumer);
given(messageConsumer.receive()).willReturn(textMessage);
given(messageConsumer.receive(timeout)).willReturn(textMessage);
verify(this.connection).start();
verify(this.connection).close();
if (useTransactedTemplate()) {
verify(this.session).commit();
代码示例来源:origin: spring-projects/spring-framework
Session tas = tac.createSession(false, Session.AUTO_ACKNOWLEDGE);
tas.getTransacted();
tas.close();
tac.close();
verify(this.connection).start();
if (useTransactedTemplate()) {
verify(this.session).commit();
verify(this.connection).close();
代码示例来源:origin: apache/storm
/**
* Initializes JMS resources.
*/
@Override
public void prepare(Map<String, Object> topoConf, TopologyContext context,
OutputCollector collector) {
if (this.jmsProvider == null || this.producer == null) {
throw new IllegalStateException("JMS Provider and MessageProducer not set.");
}
this.collector = collector;
LOG.debug("Connecting JMS..");
try {
ConnectionFactory cf = this.jmsProvider.connectionFactory();
Destination dest = this.jmsProvider.destination();
this.connection = cf.createConnection();
this.session = connection.createSession(this.jmsTransactional,
this.jmsAcknowledgeMode);
this.messageProducer = session.createProducer(dest);
connection.start();
} catch (Exception e) {
LOG.warn("Error creating JMS connection.", e);
}
}
}
代码示例来源:origin: apache/activemq
@Override
protected void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.start();
factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
consumerConnection = factory.createConnection();
consumerConnection.start();
producerConnection = factory.createConnection();
producerConnection.start();
consumerSession = consumerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
topic = consumerSession.createTopic(getName());
producerSession = producerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
consumer = consumerSession.createConsumer(topic);
producer = producerSession.createProducer(topic);
}
代码示例来源:origin: spring-projects/spring-framework
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
given(connection.createSession(this.container.isSessionTransacted(),
this.container.getSessionAcknowledgeMode())).willReturn(session);
verify(connection).start();
代码示例来源:origin: spring-projects/spring-framework
scf.setReconnectOnException(false);
Connection con1 = scf.createTopicConnection();
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.getTransacted();
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
con1.start();
TopicConnection con2 = scf.createTopicConnection();
Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
session2.close();
con2.start();
con1.close();
con2.close();
代码示例来源:origin: apache/activemq
@Before
public void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.start();
factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
producerConnection = factory.createConnection();
producerConnection.start();
producerSession = producerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
queue = producerSession.createQueue(getClass().getName());
producer = producerSession.createProducer(queue);
}
代码示例来源:origin: apache/rocketmq-externals
@Test
public void testStartIdempotency() throws Exception {
JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new
URI("rocketmq://xxx?consumerId=" + consumerId + "&nameServer=" + nameServer));
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
checkConsumerState(consumerId, true, false);
try {
Destination destination = session.createTopic(topic + ":" + messageType);
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(listener);
checkConsumerState(consumerId, false, false);
((JmsBaseMessageConsumer) consumer).startConsumer();
checkConsumerState(consumerId, false, true);
Destination destination1 = session.createTopic(topic2 + ":" + messageType);
MessageConsumer consumer1 = session.createConsumer(destination1);
consumer1.setMessageListener(listener);
((JmsBaseMessageConsumer) consumer1).startConsumer();
checkConsumerState(consumerId, false, true);
//the start is idempotent
connection.start();
connection.start();
Thread.sleep(5000);
}
finally {
connection.close();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testContextRefreshedEventStartsTheConnectionByDefault() throws Exception {
MessageConsumer messageConsumer = mock(MessageConsumer.class);
Session session = mock(Session.class);
// Queue gets created in order to create MessageConsumer for that Destination...
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
// and then the MessageConsumer gets created...
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer); // no MessageSelector...
Connection connection = mock(Connection.class);
// session gets created in order to register MessageListener...
given(connection.createSession(this.container.isSessionTransacted(),
this.container.getSessionAcknowledgeMode())).willReturn(session);
// and the connection is start()ed after the listener is registered...
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new TestMessageListener());
this.container.afterPropertiesSet();
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
verify(connection).setExceptionListener(this.container);
verify(connection).start();
}
代码示例来源:origin: spring-projects/spring-framework
scf.setReconnectOnException(false);
Connection con1 = scf.createQueueConnection();
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.rollback();
session1.close();
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
con1.start();
QueueConnection con2 = scf.createQueueConnection();
Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
con1.close();
con2.close();
内容来源于网络,如有侵权,请联系作者删除!