本文整理汇总了Java中javax.jms.QueueReceiver类的典型用法代码示例。如果您正苦于以下问题:Java QueueReceiver类的具体用法?Java QueueReceiver怎么用?Java QueueReceiver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueueReceiver类属于javax.jms包,在下文中一共展示了QueueReceiver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetQueue
import javax.jms.QueueReceiver; //导入依赖的package包/类
@Test
public void testGetQueue() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueReceiver receiver = session.createReceiver(queue);
assertNotNull(receiver.getQueue());
assertSame(queue, receiver.getQueue());
receiver.close();
try {
receiver.getQueue();
fail("Cannot read topic on closed receiver");
} catch (IllegalStateException ise) {}
}
示例2: testSpecificConsumerRetrieval
import javax.jms.QueueReceiver; //导入依赖的package包/类
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testSpecificConsumerRetrieval(String username, String password,
String hostname, String port) throws Exception {
String queueName = "testSpecificConsumerRetrieval";
// Create a durable queue using a JMS client
InitialContext initialContextForQueue = ClientHelper
.getInitialContextBuilder(username, password, hostname, port)
.withQueue(queueName)
.build();
QueueConnectionFactory connectionFactory
= (QueueConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
QueueConnection connection = connectionFactory.createQueueConnection();
connection.start();
QueueSession queueSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(queueName);
QueueReceiver receiver = queueSession.createReceiver(queue);
HttpGet getAllConsumers = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
+ "/" + queueName + "/consumers");
CloseableHttpResponse response = client.execute(getAllConsumers);
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
String body = EntityUtils.toString(response.getEntity());
ConsumerMetadata[] consumers = objectMapper.readValue(body, ConsumerMetadata[].class);
Assert.assertTrue(consumers.length > 0, "Number of consumers returned is incorrect.");
int id = consumers[0].getId();
HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/"
+ queueName + "/consumers/" + id);
response = client.execute(getConsumer);
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
String consumerString = EntityUtils.toString(response.getEntity());
ConsumerMetadata consumerMetadata = objectMapper.readValue(consumerString, ConsumerMetadata.class);
Assert.assertEquals(consumerMetadata.getId().intValue(), id, "incorrect message id");
receiver.close();
queueSession.close();
connection.close();
}
示例3: closeConsumer
import javax.jms.QueueReceiver; //导入依赖的package包/类
/**
* Close a JMS {@link MessageConsumer}.
* @param messageConsumer JMS Message Consumer that needs to be closed.
* @throws JMSException if an error occurs while closing the consumer.
*/
public void closeConsumer(MessageConsumer messageConsumer) throws JMSException {
if (messageConsumer != null) {
if (logger.isDebugEnabled()) {
logger.debug("Closing a JMS Message Consumer of: " + this.connectionFactoryString);
}
if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0
.equals(jmsSpec))) {
messageConsumer.close();
} else {
if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
if (messageConsumer instanceof QueueReceiver) {
((QueueReceiver) messageConsumer).close();
}
} else {
if (messageConsumer instanceof TopicSubscriber) {
((TopicSubscriber) messageConsumer).close();
}
}
}
}
}
示例4: testGetQueue
import javax.jms.QueueReceiver; //导入依赖的package包/类
@Test
public void testGetQueue() throws Exception {
Connection consumerConnection = null;
try {
consumerConnection = createConnection();
Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
Queue q = ((QueueReceiver) queueConsumer).getQueue();
ProxyAssertSupport.assertEquals(queue1, q);
} finally {
if (consumerConnection != null) {
consumerConnection.close();
}
}
}
示例5: testGetQueueOnClosedConsumer
import javax.jms.QueueReceiver; //导入依赖的package包/类
@Test
public void testGetQueueOnClosedConsumer() throws Exception {
Connection consumerConnection = null;
try {
consumerConnection = createConnection();
Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
queueConsumer.close();
try {
((QueueReceiver) queueConsumer).getQueue();
Assert.fail("must throw a JMS IllegalStateException");
} catch (javax.jms.IllegalStateException e) {
// OK
}
} finally {
if (consumerConnection != null) {
consumerConnection.close();
}
}
}
示例6: testCreateReceiverWithMessageSelector
import javax.jms.QueueReceiver; //导入依赖的package包/类
/**
* com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
*/
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
QueueConnection qc = null;
try {
qc = createQueueConnection();
QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");
qc.start();
TextMessage m = qs.createTextMessage();
m.setText("one");
m.setBooleanProperty("targetMessage", false);
QueueSender qsender = qs.createSender(queue1);
qsender.send(m);
m.setText("two");
m.setBooleanProperty("targetMessage", true);
qsender.send(m);
TextMessage rm = (TextMessage) qreceiver.receive(1000);
ProxyAssertSupport.assertEquals("two", rm.getText());
} finally {
if (qc != null) {
qc.close();
}
Thread.sleep(2000);
removeAllMessages(queue1.getQueueName(), true);
checkEmpty(queue1);
}
}
示例7: createReceiver
import javax.jms.QueueReceiver; //导入依赖的package包/类
/**
* Create a queue receiver
*
* @param queue The queue
* @return The queue receiver
* @throws JMSException Thrown if an error occurs
*/
@Override
public QueueReceiver createReceiver(final Queue queue) throws JMSException {
lock();
try {
QueueSession session = getQueueSessionInternal();
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue);
}
QueueReceiver result = session.createReceiver(queue);
result = new ActiveMQRAQueueReceiver(result, this);
if (ActiveMQRASession.trace) {
ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result);
}
addConsumer(result);
return result;
} finally {
unlock();
}
}
示例8: createReceiver
import javax.jms.QueueReceiver; //导入依赖的package包/类
@Override
public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException
{
externalAccessLock.readLock().lock();
try
{
checkNotClosed();
LocalQueueReceiver receiver = new LocalQueueReceiver(engine,this,queue,messageSelector,idProvider.createID());
registerConsumer(receiver);
receiver.initDestination();
return receiver;
}
finally
{
externalAccessLock.readLock().unlock();
}
}
示例9: createReceiver
import javax.jms.QueueReceiver; //导入依赖的package包/类
@Override
public QueueReceiver createReceiver(Queue queue, String messageSelector) throws JMSException
{
externalAccessLock.readLock().lock();
try
{
checkNotClosed();
RemoteQueueReceiver receiver = new RemoteQueueReceiver(idProvider.createID(),
this,
DestinationTools.asRef(queue),
messageSelector);
registerConsumer(receiver);
receiver.remoteInit();
return receiver;
}
finally
{
externalAccessLock.readLock().unlock();
}
}
示例10: testQueueReceiversAndTopicSubscriber
import javax.jms.QueueReceiver; //导入依赖的package包/类
public void testQueueReceiversAndTopicSubscriber() throws Exception
{
Queue queue = new AMQAnyDestination("ADDR:my-queue; {create: always}");
Topic topic = new AMQAnyDestination("ADDR:amq.topic/test");
QueueSession qSession = ((AMQConnection)_connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = qSession.createReceiver(queue);
TopicSession tSession = ((AMQConnection)_connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber sub = tSession.createSubscriber(topic);
Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod1 = ssn.createProducer(ssn.createQueue("ADDR:my-queue"));
prod1.send(ssn.createTextMessage("test1"));
MessageProducer prod2 = ssn.createProducer(ssn.createTopic("ADDR:amq.topic/test"));
prod2.send(ssn.createTextMessage("test2"));
Message msg1 = receiver.receive();
assertNotNull(msg1);
assertEquals("test1",((TextMessage)msg1).getText());
Message msg2 = sub.receive();
assertNotNull(msg2);
assertEquals("test2",((TextMessage)msg2).getText());
}
示例11: initQueueReceiver
import javax.jms.QueueReceiver; //导入依赖的package包/类
/**
* Prepares the QueueReceiver.
*/
public synchronized void initQueueReceiver() throws JMSException, NamingException {
//first of all we have to inititiate the QueueSession
//(without this we can't instantiate a QueueReceiver)
initQueueSession();
//get the QueueReceiver from our QueueSession
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
logger.debug("Queue receiver created");
//if set we pass our ExtendedMessageListener to the QueueReceiver as MessageListener
if (messageListener != null) {
queueReceiver.setMessageListener(messageListener);
}
//start listening to JMS
queueConnection.start();
logger.debug("Queue connection started");
}
示例12: start
import javax.jms.QueueReceiver; //导入依赖的package包/类
public void start(){
new Thread(new Runnable() {
public void run() {
try {
QueueConnectionFactory connectionFactory = (QueueConnectionFactory)context.lookup("factory/QueueConnectionFactory");
QueueConnection queueConnection = connectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(destinationName);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
queueReceiver.setMessageListener(MyAsyncReader.this);
queueConnection.start();
System.out.println("thred terminated");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
示例13: openThread
import javax.jms.QueueReceiver; //导入依赖的package包/类
public Map openThread() throws ListenerException {
Map threadContext = new HashMap();
try {
if (!isSessionsArePooled()) {
QueueSession session = createSession();
threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);
QueueReceiver receiver;
receiver = getServiceReceiver(session);
threadContext.put(THREAD_CONTEXT_RECEIVER_KEY, receiver);
}
return threadContext;
} catch (IfsaException e) {
throw new ListenerException(getLogPrefix()+"exception in openThread()", e);
}
}
示例14: getProviderSelector
import javax.jms.QueueReceiver; //导入依赖的package包/类
protected synchronized String getProviderSelector() {
if (providerSelector==null && useSelectorsForProviders()) {
try {
providerSelector=""; // set default, also to avoid re-evaluation time and time again for lower ifsa-versions.
if (messageProtocol.equals(IfsaMessageProtocolEnum.REQUEST_REPLY)) {
providerSelector=IFSAConstants.QueueReceiver.SELECTOR_RR;
}
if (messageProtocol.equals(IfsaMessageProtocolEnum.FIRE_AND_FORGET)) {
providerSelector=IFSAConstants.QueueReceiver.SELECTOR_FF;
}
} catch (Throwable t) {
log.debug(getLogPrefix()+"exception determining selector, probably lower ifsa version, ignoring");
}
}
return providerSelector;
}
示例15: createReceiver
import javax.jms.QueueReceiver; //导入依赖的package包/类
public QueueReceiver createReceiver(Queue queue) throws JMSException {
lock();
try {
QueueSession session = getQueueSession();
if (trace)
log.trace("createReceiver " + session + " queue=" + queue);
QueueReceiver result = session.createReceiver(queue);
result = new JmsQueueReceiver(result, this);
if (trace)
log.trace("createdReceiver " + session + " receiver=" + result);
addConsumer(result);
return result;
} finally {
unlock();
}
}