本文整理匯總了Java中javax.jms.Queue類的典型用法代碼示例。如果您正苦於以下問題:Java Queue類的具體用法?Java Queue怎麽用?Java Queue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Queue類屬於javax.jms包,在下文中一共展示了Queue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import javax.jms.Queue; //導入依賴的package包/類
@BeforeEach
public void setUp() throws JMSException {
initMocks(this);
when(mockEvent.getTarget()).thenReturn(of(rdf.createIRI("trellis:repository/resource")));
when(mockEvent.getAgents()).thenReturn(singleton(Trellis.AdministratorAgent));
when(mockEvent.getCreated()).thenReturn(time);
when(mockEvent.getIdentifier()).thenReturn(rdf.createIRI("urn:test"));
when(mockEvent.getTypes()).thenReturn(singleton(AS.Update));
when(mockEvent.getTargetTypes()).thenReturn(singleton(LDP.RDFSource));
when(mockEvent.getInbox()).thenReturn(empty());
when(mockConnection.createSession(anyBoolean(), eq(AUTO_ACKNOWLEDGE))).thenReturn(mockSession);
when(mockSession.createQueue(eq(queueName))).thenReturn(mockQueue);
when(mockSession.createTextMessage(anyString())).thenReturn(mockMessage);
when(mockSession.createProducer(any(Queue.class))).thenReturn(mockProducer);
doNothing().when(mockProducer).send(any(TextMessage.class));
}
示例2: createQueue
import javax.jms.Queue; //導入依賴的package包/類
/**
* Deals with reconnecting or if broker gone down, fails
*
* @param queueName
* @return
* @throws JMSException
*/
protected Queue createQueue(String queueName) throws JMSException {
// Deals with reconnecting or if broker gone down, fails
try {
if (connection==null) createConnection();
if (qSession == null) createQSession();
return qSession.createQueue(queueName);
} catch (Exception ne) {
createConnection();
createQSession();
return qSession.createQueue(queueName);
}
}
示例3: sendRequest
import javax.jms.Queue; //導入依賴的package包/類
public String sendRequest(Optional<String> routeId) {
CompactRequest req = new CompactRequest(routeId.orElse("asdf"));
try {
TextMessage msg = context.createTextMessage(JsonMapper.serializeOrThrow(req));
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
Queue answerQ = context.createTemporaryQueue();
msg.setJMSReplyTo(answerQ);
context.createProducer().send(minQ, msg);
Message response = context.createConsumer(answerQ).receive();
if (response instanceof TextMessage) {
return ((TextMessage) response).getText();
}
return "";
} catch (JMSException e) {
return e.getMessage();
}
}
示例4: testReceiveNoWait
import javax.jms.Queue; //導入依賴的package包/類
@Test
public void testReceiveNoWait() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
Session session = connection.createSession();
Queue queue = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(queue, "Color = Red");
assertNull(consumer.receiveNoWait());
consumer.close();
try {
consumer.receiveNoWait();
fail("Should not be able to interact with closed consumer");
} catch (IllegalStateException ise) {}
}
示例5: doTestCreateQueueSender
import javax.jms.Queue; //導入依賴的package包/類
private void doTestCreateQueueSender(boolean useAnonymousProducers) throws JMSException {
cf.setUseAnonymousProducers(useAnonymousProducers);
JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue1 = session.createTemporaryQueue();
Queue queue2 = session.createTemporaryQueue();
JmsPoolQueueSender sender1 = (JmsPoolQueueSender) session.createSender(queue1);
JmsPoolQueueSender sender2 = (JmsPoolQueueSender) session.createSender(queue2);
if (useAnonymousProducers) {
assertSame(sender1.getMessageProducer(), sender2.getMessageProducer());
} else {
assertNotSame(sender1.getMessageProducer(), sender2.getMessageProducer());
}
connection.close();
}
示例6: testGetTopicSubscriber
import javax.jms.Queue; //導入依賴的package包/類
@Test
public void testGetTopicSubscriber() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
JmsPoolQueueSender sender = (JmsPoolQueueSender) session.createSender(queue);
assertNotNull(sender.getQueueSender());
assertTrue(sender.getQueueSender() instanceof MockJMSQueueSender);
sender.close();
try {
sender.getQueueSender();
fail("Cannot read state on closed sender");
} catch (IllegalStateException ise) {}
}
示例7: testGetMessageSelector
import javax.jms.Queue; //導入依賴的package包/類
@Test
public void testGetMessageSelector() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueBrowser browser = session.createBrowser(queue, "color = red");
assertNotNull(browser.getMessageSelector());
assertEquals("color = red", browser.getMessageSelector());
browser.close();
try {
browser.getMessageSelector();
fail("Should not be able to use a closed browser");
} catch (IllegalStateException ise) {
}
}
示例8: testGetEnumeration
import javax.jms.Queue; //導入依賴的package包/類
@Test
public void testGetEnumeration() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueBrowser browser = session.createBrowser(queue);
assertNotNull(browser.getEnumeration());
browser.close();
try {
browser.getEnumeration();
fail("Should not be able to use a closed browser");
} catch (IllegalStateException ise) {
}
}
示例9: sendRequest
import javax.jms.Queue; //導入依賴的package包/類
public String sendRequest(Optional<String> routeId) {
DetailsRequest req = new DetailsRequest(routeId.orElse("asdf"));
try {
TextMessage msg = context.createTextMessage(JsonMapper.serializeOrThrow(req));
msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
Queue answerQ = context.createTemporaryQueue();
msg.setJMSReplyTo(answerQ);
context.createProducer().send(minQ, msg);
Message response = context.createConsumer(answerQ).receive();
if (response instanceof TextMessage) {
return ((TextMessage) response).getText();
}
return "";
} catch (JMSException e) {
return e.getMessage();
}
}
示例10: run
import javax.jms.Queue; //導入依賴的package包/類
@Override
public void run(String... strings) throws Exception {
final String messageText = "Hello World";
LOG.info("============= Sending " + messageText);
this.jmsTemplate.send("example", new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
Queue replyQueue = session.createQueue("reply-queue");
TextMessage message = session.createTextMessage(messageText);
message.setJMSCorrelationID(correlationID.toString());
message.setJMSReplyTo(replyQueue);
return message;
}
});
}
示例11: init
import javax.jms.Queue; //導入依賴的package包/類
/**
* Inits the.
*
* @throws JMSException the jMS exception
*/
public void init() throws JMSException {
connection = connFactory.createConnection();
// lets make it transactional
session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue controllerQueue = session.createQueue(ctrlrQueueName);
MessageConsumer consumer = session.createConsumer(controllerQueue);
consumer.setMessageListener(this);
connection.start();
logger.info(">>>>>>>>>>>>>>>>Inductor Listener Waiting for messages...");
}
示例12: getQueueSender
import javax.jms.Queue; //導入依賴的package包/類
private QueueSender getQueueSender(Queue destination) throws JMSException {
QueueSender result = null;
if (useAnonymousProducers) {
result = safeGetSessionHolder().getOrCreateSender();
} else {
result = ((QueueSession) getInternalSession()).createSender(destination);
}
return result;
}
示例13: createQueue
import javax.jms.Queue; //導入依賴的package包/類
@Override
public Queue createQueue(String queueName) {
try {
return getSession().createQueue(queueName);
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
}
示例14: createBrowser
import javax.jms.Queue; //導入依賴的package包/類
@Override
public QueueBrowser createBrowser(Queue queue) {
try {
return startIfNeeded(getSession().createBrowser(queue));
} catch (JMSException jmse) {
throw JMSExceptionSupport.createRuntimeException(jmse);
}
}
示例15: getJmsQueue
import javax.jms.Queue; //導入依賴的package包/類
/**
* Get the OSCM task queue
*
* @param context
* a JNDI context
* @return the task queue
*/
private Queue getJmsQueue(InitialContext context) {
try {
Object lookup = context.lookup(JMS_QUEUE_JNDI_NAME);
return Queue.class.cast(lookup);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}