本文整理汇总了Java中org.springframework.jms.support.JmsUtils类的典型用法代码示例。如果您正苦于以下问题:Java JmsUtils类的具体用法?Java JmsUtils怎么用?Java JmsUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JmsUtils类属于org.springframework.jms.support包,在下文中一共展示了JmsUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearResources
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
private void clearResources() {
if (sharedConnectionEnabled()) {
synchronized (sharedConnectionMonitor) {
JmsUtils.closeMessageConsumer(this.consumer);
JmsUtils.closeSession(this.session);
}
}
else {
JmsUtils.closeMessageConsumer(this.consumer);
JmsUtils.closeSession(this.session);
}
if (this.consumer != null) {
synchronized (lifecycleMonitor) {
registeredWithDestination--;
}
}
this.consumer = null;
this.session = null;
}
示例2: doShutdown
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Destroy the registered JMS Sessions and associated MessageConsumers.
*/
@Override
protected void doShutdown() throws JMSException {
synchronized (this.consumersMonitor) {
if (this.consumers != null) {
logger.debug("Closing JMS MessageConsumers");
for (MessageConsumer consumer : this.consumers) {
JmsUtils.closeMessageConsumer(consumer);
}
logger.debug("Closing JMS Sessions");
for (Session session : this.sessions) {
JmsUtils.closeSession(session);
}
}
}
}
示例3: executeRequest
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Execute the given remote invocation, sending an invoker request message
* to this accessor's target queue and waiting for a corresponding response.
* @param invocation the RemoteInvocation to execute
* @return the RemoteInvocationResult object
* @throws JMSException in case of JMS failure
* @see #doExecuteRequest
*/
protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException {
Connection con = createConnection();
Session session = null;
try {
session = createSession(con);
Queue queueToUse = resolveQueue(session);
Message requestMessage = createRequestMessage(session, invocation);
con.start();
Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage);
if (responseMessage != null) {
return extractInvocationResult(responseMessage);
}
else {
return onReceiveTimeout(invocation);
}
}
finally {
JmsUtils.closeSession(session);
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true);
}
}
示例4: doExecuteRequest
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Actually execute the given request, sending the invoker request message
* to the specified target queue and waiting for a corresponding response.
* <p>The default implementation is based on standard JMS send/receive,
* using a {@link javax.jms.TemporaryQueue} for receiving the response.
* @param session the JMS Session to use
* @param queue the resolved target Queue to send to
* @param requestMessage the JMS Message to send
* @return the RemoteInvocationResult object
* @throws JMSException in case of JMS failure
*/
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
TemporaryQueue responseQueue = null;
MessageProducer producer = null;
MessageConsumer consumer = null;
try {
responseQueue = session.createTemporaryQueue();
producer = session.createProducer(queue);
consumer = session.createConsumer(responseQueue);
requestMessage.setJMSReplyTo(responseQueue);
producer.send(requestMessage);
long timeout = getReceiveTimeout();
return (timeout > 0 ? consumer.receive(timeout) : consumer.receive());
}
finally {
JmsUtils.closeMessageConsumer(consumer);
JmsUtils.closeMessageProducer(producer);
if (responseQueue != null) {
responseQueue.delete();
}
}
}
示例5: execute
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
@Override
public <T> T execute(final Destination destination, final ProducerCallback<T> action) throws JmsException {
Assert.notNull(action, "Callback object must not be null");
return execute(new SessionCallback<T>() {
@Override
public T doInJms(Session session) throws JMSException {
MessageProducer producer = createProducer(session, destination);
try {
return action.doInJms(session, producer);
}
finally {
JmsUtils.closeMessageProducer(producer);
}
}
}, false);
}
示例6: doSend
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Send the given JMS message.
* @param session the JMS Session to operate on
* @param destination the JMS Destination to send to
* @param messageCreator callback to create a JMS Message
* @throws JMSException if thrown by JMS API methods
*/
protected void doSend(Session session, Destination destination, MessageCreator messageCreator)
throws JMSException {
Assert.notNull(messageCreator, "MessageCreator must not be null");
MessageProducer producer = createProducer(session, destination);
try {
Message message = messageCreator.createMessage(session);
if (logger.isDebugEnabled()) {
logger.debug("Sending created message: " + message);
}
doSend(producer, message);
// Check commit - avoid commit call within a JTA transaction.
if (session.getTransacted() && isSessionLocallyTransacted(session)) {
// Transacted session created by this template -> commit.
JmsUtils.commitIfNecessary(session);
}
}
finally {
JmsUtils.closeMessageProducer(producer);
}
}
示例7: executeLocal
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* 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.
*/
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 = getConnectionFactory().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);
}
}
示例8: browseSelected
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
@Override
public <T> T browseSelected(final Queue queue, final String messageSelector, final BrowserCallback<T> action)
throws JmsException {
Assert.notNull(action, "Callback object must not be null");
return execute(new SessionCallback<T>() {
@Override
public T doInJms(Session session) throws JMSException {
QueueBrowser browser = createBrowser(session, queue, messageSelector);
try {
return action.doInJms(session, browser);
}
finally {
JmsUtils.closeQueueBrowser(browser);
}
}
}, true);
}
示例9: SendMessage
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
@Override
public void SendMessage(Destination destination, final byte[] message) {
jmsTemplate.send(destination, new MessageCreator() {
public Message createMessage(Session session) {
BytesMessage msg;
try {
msg = session.createBytesMessage();
msg.writeBytes(message);
log.debug("报文发送完成");
} catch (JMSException e) {
throw JmsUtils.convertJmsAccessException(e);
}
return msg;
}
});
}
示例10: ReceiveMessage
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
@Override
public byte[] ReceiveMessage(Destination destination, long timeout) {
byte[] msg = null;
jmsTemplate.setReceiveTimeout(timeout);
Message message = jmsTemplate.receive(destination);
try {
if (message instanceof TextMessage) {
msg = ((TextMessage) message).getText().getBytes();
} else if (message instanceof BytesMessage) {
BytesMessage bMsg = (BytesMessage) message;
msg = new byte[(int) bMsg.getBodyLength()];
bMsg.readBytes(msg);
} else if (message instanceof ObjectMessage) {
ObjectMessage oMsg = (ObjectMessage) message;
msg = (byte[]) oMsg.getObject();
}
} catch (JMSException e) {
throw JmsUtils.convertJmsAccessException(e);
}
return msg;
}
示例11: doSendToDestination
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
private Object doSendToDestination(final Destination destination,
final MessageCreator messageCreator,
final MessageSentCallback callback,
final Session session) throws JMSException {
Assert.notNull(messageCreator, "MessageCreator must not be null");
MessageProducer producer = createProducer(session, destination);
Message message;
try {
message = messageCreator.createMessage(session);
doSend(producer, message);
if (message != null && callback != null) {
callback.sent(session, message, destination);
}
// Check commit - avoid commit call within a JTA transaction.
if (session.getTransacted() && isSessionLocallyTransacted(session)) {
// Transacted session created by this template -> commit.
JmsUtils.commitIfNecessary(session);
}
} finally {
JmsUtils.closeMessageProducer(producer);
}
return null;
}
示例12: testConnectionOnStartup
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Pre tests the connection before starting the listening.
* <p/>
* In case of connection failure the exception is thrown which prevents Camel from starting.
*
* @throws FailedToCreateProducerException is thrown if testing the connection failed
*/
protected void testConnectionOnStartup() throws FailedToCreateProducerException {
try {
CamelJmsTemplate template = (CamelJmsTemplate) getInOnlyTemplate();
if (log.isDebugEnabled()) {
log.debug("Testing JMS Connection on startup for destination: " + template.getDefaultDestinationName());
}
Connection conn = template.getConnectionFactory().createConnection();
JmsUtils.closeConnection(conn);
log.debug("Successfully tested JMS Connection on startup for destination: " + template.getDefaultDestinationName());
} catch (Exception e) {
throw new FailedToCreateProducerException(getEndpoint(), e);
}
}
示例13: getCloseAction
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
private Runnable getCloseAction(final String tickDistributionSpecification, final ConsumerRecord record) {
return new Runnable() {
@Override
public void run() {
record.getReceiving().remove(tickDistributionSpecification);
if (record.getReceiving().isEmpty()) {
s_logger.debug("Closing connection after last unsubscribe {}", tickDistributionSpecification);
JmsUtils.closeMessageConsumer(record.getConsumer());
for (String receiving : record.getAllReceiving()) {
_messageConsumersBySpec.remove(receiving);
}
} else {
//TODO: Should I shrink the subscription?
s_logger.debug("Not closing composite connection remaining subscribtions {}", record.getReceiving());
}
}
};
}
示例14: sendResponse
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Overrides the superclass method to use the JMS 1.0.2 API to send a response.
* <p>Uses the JMS pub-sub API if the given destination is a topic,
* else uses the JMS queue API.
*/
protected void sendResponse(Session session, Destination destination, Message response) throws JMSException {
MessageProducer producer = null;
try {
if (destination instanceof Topic) {
producer = ((TopicSession) session).createPublisher((Topic) destination);
postProcessProducer(producer, response);
((TopicPublisher) producer).publish(response);
}
else {
producer = ((QueueSession) session).createSender((Queue) destination);
postProcessProducer(producer, response);
((QueueSender) producer).send(response);
}
}
finally {
JmsUtils.closeMessageProducer(producer);
}
}
示例15: executeRequest
import org.springframework.jms.support.JmsUtils; //导入依赖的package包/类
/**
* Execute the given remote invocation, sending an invoker request message
* to this accessor's target queue and waiting for a corresponding response.
* @param invocation the RemoteInvocation to execute
* @return the RemoteInvocationResult object
* @throws JMSException in case of JMS failure
* @see #doExecuteRequest
*/
protected RemoteInvocationResult executeRequest(RemoteInvocation invocation) throws JMSException {
Connection con = createConnection();
Session session = null;
try {
session = createSession(con);
Queue queueToUse = resolveQueue(session);
Message requestMessage = createRequestMessage(session, invocation);
con.start();
Message responseMessage = doExecuteRequest(session, queueToUse, requestMessage);
return extractInvocationResult(responseMessage);
}
finally {
JmsUtils.closeSession(session);
ConnectionFactoryUtils.releaseConnection(con, getConnectionFactory(), true);
}
}