當前位置: 首頁>>代碼示例>>Java>>正文


Java QueueSender類代碼示例

本文整理匯總了Java中javax.jms.QueueSender的典型用法代碼示例。如果您正苦於以下問題:Java QueueSender類的具體用法?Java QueueSender怎麽用?Java QueueSender使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


QueueSender類屬於javax.jms包,在下文中一共展示了QueueSender類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetQueue

import javax.jms.QueueSender; //導入依賴的package包/類
@Test
public void testGetQueue() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueSender sender = session.createSender(queue);

    assertNotNull(sender.getQueue());
    assertSame(queue, sender.getQueue());

    sender.close();

    try {
        sender.getQueue();
        fail("Cannot read topic on closed sender");
    } catch (IllegalStateException ise) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolQueueSenderTest.java

示例2: testSenderAndPublisherDest

import javax.jms.QueueSender; //導入依賴的package包/類
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
    JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory();
    pcf.setConnectionFactory(new ActiveMQXAConnectionFactory(
        "vm://test?broker.persistent=false&broker.useJmx=false"));

    QueueConnection connection = pcf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueSender sender = session.createSender(session.createQueue("AA"));
    assertNotNull(sender.getQueue().getQueueName());

    connection.close();

    TopicConnection topicConnection = pcf.createTopicConnection();
    TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
    assertNotNull(topicPublisher.getTopic().getTopicName());

    topicConnection.close();
    pcf.stop();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:22,代碼來源:XAConnectionPoolTest.java

示例3: invokeJMS

import javax.jms.QueueSender; //導入依賴的package包/類
/** Send a JSON message to our notification queue.
 */
public void invokeJMS(JsonObject json) throws JMSException, NamingException {
	if (!initialized) initialize(); //gets our JMS managed resources (Q and QCF)

	QueueConnection connection = queueCF.createQueueConnection();
	QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

	TextMessage message = session.createTextMessage(json.toString());
	System.out.println("Sending "+json.toString()+" to "+queue.getQueueName());
	QueueSender sender = session.createSender(queue);
	sender.send(message);

	sender.close();
	session.close();
	connection.close();

	System.out.println("Message sent successfully!");
}
 
開發者ID:IBMStockTrader,項目名稱:loyalty-level,代碼行數:20,代碼來源:LoyaltyLevel.java

示例4: processAndReply

import javax.jms.QueueSender; //導入依賴的package包/類
@Test
public void processAndReply() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDefaultResponseDestination(replyDestination);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);
	assertDefaultListenerMethodInvocation();

	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:MethodJmsListenerEndpointTests.java

示例5: processAndReplyWithSendTo

import javax.jms.QueueSender; //導入依賴的package包/類
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, boolean pubSubDomain) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, "replyDestination", pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, "replyDestination", pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:MethodJmsListenerEndpointTests.java

示例6: send

import javax.jms.QueueSender; //導入依賴的package包/類
/**
 * Sends a message to the myWMS application inside the application
 * server.
 * 
 * @param mfcMessage the message to be send
 * @throws JMSException
 * @throws NamingException
 */
public void send(MFCMessage mfcMessage)
    throws JMSException,
        NamingException
{

    // create the jms session
    QueueSession session =
        connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    // lookup of the jms queue over jndi
    Queue outputQueue =
        (Queue) context.lookup("queue/" + OUTPUT_QUEUE_NAME);

    // create the message publisher
    QueueSender sender = session.createSender(outputQueue);

    ObjectMessage objectMessage = session.createObjectMessage();
    objectMessage.setObject(mfcMessage);
    objectMessage.setJMSTimestamp(System.currentTimeMillis());

    sender.send(objectMessage);
    sender.close();

    session.close();
}
 
開發者ID:salimvanak,項目名稱:myWMS,代碼行數:34,代碼來源:ServerConnection.java

示例7: sendTextMessage

import javax.jms.QueueSender; //導入依賴的package包/類
public String sendTextMessage(String queueName, String msg) throws Exception {

        if (StringUtils.isBlank(queueName)) {
            throw new IllegalArgumentException("Queue can not be null!");
        }

        if (logger.isDebugEnabled()) {

            StringBuilder sb = new StringBuilder();
            sb.append("sendTextMessage :: Setting params... \n");
            sb.append("\t- queueManagerName = '{}' \n");
            sb.append("\t- queueName = '{}' \n");
            sb.append("\t- replyToQueueName = '{}' \n");
            sb.append("\t- hostname = '{}' \n");
            sb.append("\t- port = '{}' \n");
            sb.append("\t- channel = '{}' \n");

            LoggerUtils.logDebug(logger, sb.toString(), queueManagerName, queueName, responseQueueName, hostname, port,
                channel);
        }

        QueueConnection connection = null;
        TextMessage requestMessage;
        try {

            QueueConnectionFactory qcf = new MQQueueConnectionFactory();
            ((MQQueueConnectionFactory) qcf).setIntProperty(WMQConstants.WMQ_CONNECTION_MODE,
                WMQConstants.WMQ_CM_CLIENT);
            ((MQQueueConnectionFactory) qcf).setHostName(hostname);
            ((MQQueueConnectionFactory) qcf).setPort(port);
            ((MQQueueConnectionFactory) qcf).setQueueManager(queueManagerName);
            if (StringUtils.isNotBlank(channel)) {
                ((MQQueueConnectionFactory) qcf).setChannel(channel);
            }
            // ((MQQueueConnectionFactory) qcf).setCCSID(500);

            connection = qcf.createQueueConnection(" ", " ");
            connection.start();

            // Create a session
            MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);

            // Get a request queue
            Queue queue = ((MQQueueSession) session).createQueue("queue://" + queueManagerName + "/" + queueName);

            // Create message sender
            QueueSender sender = session.createSender(queue);
            requestMessage = session.createTextMessage(msg);
            // m1.setIntProperty("JMS_", MQC.MQENC_NATIVE);

            // Setting reply-to queue
            Queue queueResp = ((MQQueueSession) session)
                .createQueue("queue://" + queueManagerName + "/" + responseQueueName);
            requestMessage.setJMSReplyTo(queueResp);
            LoggerUtils.logDebug(logger, "sendTextMessage :: message \n{}", requestMessage.toString());

            sender.send(requestMessage);
            LoggerUtils.logDebug(logger, "sendTextMessage :: Message Sent! ID: {} \n",
                requestMessage.getJMSMessageID());

            return requestMessage.getJMSMessageID();

        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException je) {
                    je.printStackTrace();
                }
            }
        }
    }
 
開發者ID:dalifreire,項目名稱:mq-gateway,代碼行數:73,代碼來源:MQGatewayImpl.java

示例8: acknowledge

import javax.jms.QueueSender; //導入依賴的package包/類
private void acknowledge(Message jmsMessage, String msgid) throws JMSException, ServiceLocatorException {
        QueueConnection connection = null;
        QueueSession session = null;
        QueueSender sender = null;
        try {
            Queue respQueue = (Queue) jmsMessage.getJMSReplyTo();
            QueueConnectionFactory qcf = JMSServices.getInstance().getQueueConnectionFactory(null);
            connection = qcf.createQueueConnection();
            session = connection.createQueueSession(false, QueueSession.DUPS_OK_ACKNOWLEDGE);
            sender = session.createSender(respQueue);
            Message respMsg = session.createTextMessage(msgid);
//        respMsg.setJMSCorrelationID(correlationId); not used
            sender.send(respMsg);
        } finally {
            if (sender != null) sender.close();
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
    }
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:20,代碼來源:InternalEventListener.java

示例9: sendMessage

import javax.jms.QueueSender; //導入依賴的package包/類
/**
 * Send a message to testInboundQueue queue
 *
 * @throws Exception
 */
private void sendMessage() throws Exception {
    InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext();
    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY);
    QueueConnection queueConnection = connectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME));

    String message = "<?xml version='1.0' encoding='UTF-8'?>" +
            "    <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " +
            "      <ser:request>" +
            "        <xsd:symbol>IBM</xsd:symbol>" +
            "      </ser:request>" +
            "    </ser:getQuote>";
    try {
        TextMessage jmsMessage = queueSession.createTextMessage(message);
        jmsMessage.setJMSType("incorrecttype");
        sender.send(jmsMessage);
    } finally {
        queueConnection.close();
    }
}
 
開發者ID:wso2,項目名稱:product-ei,代碼行數:28,代碼來源:JmsTypeHeaderInboundEndpointTestCase.java

示例10: closeProducer

import javax.jms.QueueSender; //導入依賴的package包/類
/**
 * Close a JMS {@link MessageProducer}.
 * @param messageProducer JMS Message Producer that needs to be closed.
 * @throws JMSException if an error occurs while closing the producer.
 */
public void closeProducer(MessageProducer messageProducer) throws JMSException {
    if (messageProducer != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Closing a JMS Message Producer of: " + this.connectionFactoryString);
        }
        if ((JMSConstants.JMS_SPEC_VERSION_1_1.equals(jmsSpec)) || (JMSConstants.JMS_SPEC_VERSION_2_0
                .equals(jmsSpec))) {
            messageProducer.close();
        } else {
            if (JMSConstants.JMSDestinationType.QUEUE.equals(this.destinationType)) {
                ((QueueSender) messageProducer).close();
            } else {
                ((TopicPublisher) messageProducer).close();
            }
        }
    }
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:23,代碼來源:JMSConnectionResourceFactory.java

示例11: testCreateReceiverWithMessageSelector

import javax.jms.QueueSender; //導入依賴的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);
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:41,代碼來源:QueueReceiverTest.java

示例12: createSender

import javax.jms.QueueSender; //導入依賴的package包/類
/**
 * Create a queue sender
 *
 * @param queue The queue
 * @return The queue sender
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueSender createSender(final Queue queue) throws JMSException {
   lock();
   try {
      QueueSession session = getQueueSessionInternal();

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("createSender " + session + " queue=" + queue);
      }

      QueueSender result = session.createSender(queue);
      result = new ActiveMQRAQueueSender(result, this);

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("createdSender " + session + " sender=" + result);
      }

      addProducer(result);

      return result;
   } finally {
      unlock();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:32,代碼來源:ActiveMQRASession.java

示例13: setUp

import javax.jms.QueueSender; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestContextFactory.class.getName());
    QueueConnectionFactory queueConnectionFactory = Mockito.mock(QueueConnectionFactory.class);
    Queue queue = Mockito.mock(Queue.class);
    Context context = Mockito.mock(Context.class);
    TestContextFactory.context = context;
    when(context.lookup(eq("jms/queueConnectionFactory"))).thenReturn(queueConnectionFactory);
    when(context.lookup(eq("jms/mailQueue"))).thenReturn(queue);
    queueSender = Mockito.mock(QueueSender.class);
    QueueConnection queueConnection = Mockito.mock(QueueConnection.class);
    when(queueConnectionFactory.createQueueConnection()).thenReturn(queueConnection);
    when(queueConnectionFactory.createQueueConnection(anyString(), anyString())).thenReturn(queueConnection);
    QueueSession queueSession = Mockito.mock(QueueSession.class);
    bytesMessage = Mockito.mock(BytesMessage.class);
    when(queueSession.createBytesMessage()).thenReturn(bytesMessage);
    when(queueConnection.createQueueSession(anyBoolean(), anyInt())).thenReturn(queueSession);
    when(queueSession.createSender(eq(queue))).thenReturn(queueSender);
    transport = new SmtpJmsTransport(Session.getDefaultInstance(new Properties()), new URLName("jms"));
    transportListener = Mockito.mock(TransportListener.class);
    transport.addTransportListener(transportListener);
}
 
開發者ID:m-szalik,項目名稱:javamail,代碼行數:23,代碼來源:SmtpJmsTransportTest.java

示例14: sendResponse

import javax.jms.QueueSender; //導入依賴的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);
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:24,代碼來源:MessageListenerAdapter102.java

示例15: doSend

import javax.jms.QueueSender; //導入依賴的package包/類
/**
 * This implementation overrides the superclass method to use JMS 1.0.2 API.
 */
protected void doSend(MessageProducer producer, Message message) throws JMSException {
	if (isPubSubDomain()) {
		if (isExplicitQosEnabled()) {
			((TopicPublisher) producer).publish(message, getDeliveryMode(), getPriority(), getTimeToLive());
		}
		else {
			((TopicPublisher) producer).publish(message);
		}
	}
	else {
		if (isExplicitQosEnabled()) {
			((QueueSender) producer).send(message, getDeliveryMode(), getPriority(), getTimeToLive());
		}
		else {
			((QueueSender) producer).send(message);
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:JmsTemplate102.java


注:本文中的javax.jms.QueueSender類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。