本文整理汇总了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;
}
}