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


Java QueueSender.send方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: submitJob

import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public void submitJob(AbstractFileManagementJob job) {
    ServiceLocator locator = ServiceLocatorFactory.getLocator();
    final QueueConnectionFactory factory = (QueueConnectionFactory) locator.lookup(DEFAULT_QUEUE_CONN_FACTORY);
    final Queue queue = (Queue) locator.lookup(FileManagementMDB.QUEUE_JNDI_NAME);
    QueueConnection queueConnection = null;
    QueueSession queueSession = null;
    QueueSender queueSender = null;
    try {
        queueConnection = factory.createQueueConnection();
        queueSession = queueConnection.createQueueSession(true, 0);
        queueSender = queueSession.createSender(queue);
        final ObjectMessage message = queueSession.createObjectMessage(job);
        queueSender.send(message);
    } catch (JMSException e) {
        LOG.error("Couldn't submit job to JMS", e);
    } finally {
        close(queueSender);
        close(queueSession);
        close(queueConnection);
    }
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:25,代碼來源:JmsJobSubmitter.java

示例8: testSendToQueueFailsIfNotAnonymousPublisher

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

    try {
        sender.send(session.createTemporaryQueue(), session.createTextMessage());
        fail("Should not be able to send to alternate destination");
    } catch (UnsupportedOperationException ex) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:13,代碼來源:JmsPoolQueueSenderTest.java

示例9: avisoBackOffice

import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
 * Realiza proceso de aviso a BackOffice para un tr�mite. Metemos en cola as�ncrona.
 * En caso de error lanza mensaje al log y permite continuar.
 * @param procedimiento
 */
private void avisoBackOffice(Procedimiento procedimiento,Date hasta) throws Exception{    	
		
		log.debug("Aviso a backoffice procedimiento  " + procedimiento.getIdentificador() + " (hasta " + StringUtil.fechaACadena(hasta,StringUtil.FORMATO_TIMESTAMP) + ")");
		
		// Obtenemos entradas no procesadas    		    		    	
		TramiteBandejaDelegate tbd = (TramiteBandejaDelegate) DelegateUtil.getTramiteBandejaDelegate();
		
		// Obtenemos tramites del procedimiento que tienen entradas pendientes y generamos un mensaje por tramite
		String idTramites[] = tbd.obtenerIdTramitesProcedimiento(procedimiento.getIdentificador(),ConstantesBTE.ENTRADA_NO_PROCESADA,null,hasta);
		if (idTramites != null) {
			for (int i = 0; i < idTramites.length; i++) {
		
				String  entradas [] = tbd.obtenerNumerosEntradas(procedimiento.getIdentificador(), idTramites[i], ConstantesBTE.ENTRADA_NO_PROCESADA,null,hasta);
  		
  		log.debug("Aviso de " + entradas.length + " nuevas entradas para backoffice tr�mite " + idTramites[i] + " hasta " + StringUtil.fechaACadena(hasta,StringUtil.FORMATO_TIMESTAMP) + " (Procedimiento: " + procedimiento.getIdentificador() + ")");
  		
  		if (entradas.length > 0){
		// Dejamos entrada en la cola de avisos
    	InitialContext ctx = new InitialContext();
    	String colaAvisos = (String) ctx.lookup("java:comp/env/colaAvisos");
	    Queue queue = (Queue) ctx.lookup(colaAvisos);		 
	    QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/XAConnectionFactory");
	    QueueConnection cnn = factory.createQueueConnection();
	    QueueSession sess = cnn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);    		  
		TextMessage msg = sess.createTextMessage(BteStringUtil.numeroEntradasToString(entradas));
		QueueSender sender = sess.createSender(queue);
		sender.send(msg,DeliveryMode.NON_PERSISTENT,4,0);				
  		}
			}
		}    	   	
}
 
開發者ID:GovernIB,項目名稱:sistra,代碼行數:37,代碼來源:BteProcesosFacadeEJB.java

示例10: avisoBackOffice

import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
   * Tras producirse una entrada en el BackOffice realizamos aviso inmediato si procede  
   * @param entrada
   */
  private void avisoBackOffice(String numeroEntrada) throws Exception{
  	
  	// TODO Destino cola parametrizable por properties
  	
  	// Recuperamos informacion tramite
  	TramiteBandejaDelegate td = DelegateUtil.getTramiteBandejaDelegate();
TramiteBandeja tramiteBandeja = td.obtenerTramiteBandeja(numeroEntrada);

// Comprobamos si tiene habilitado el aviso inmediato
if (tramiteBandeja.getProcedimiento().avisosEnabled() &&
	tramiteBandeja.getProcedimiento().getInmediata() == 'S'){
	
	// Dejamos entrada en la cola de avisos inmediatos
   	InitialContext ctx = new InitialContext();
   	String colaAvisos = (String) ctx.lookup("java:comp/env/colaAvisos");
    Queue queue = (Queue) ctx.lookup(colaAvisos);		    		
    QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("java:/JmsXA");
    QueueConnection cnn = factory.createQueueConnection();
    
    // Creamos sesion transacted para que hasta q no se haga commit no se env�e el mensaje
    QueueSession sess = cnn.createQueueSession(true,0);    		
    
	TextMessage msg = sess.createTextMessage(numeroEntrada);
	QueueSender sender = sess.createSender(queue);
	sender.send(msg);
	
	cnn.close();

}
  	    	
  }
 
開發者ID:GovernIB,項目名稱:sistra,代碼行數:36,代碼來源:BteSistraFacadeEJB.java

示例11: ignoreOnMessage

import javax.jms.QueueSender; //導入方法依賴的package包/類
public void ignoreOnMessage()
throws Exception
{
	Email email = new Email();
	email.sendMail(to, from, subject, "PRE TEST");

	Debugger.println(this,"Hello word");
	
	QueueConnection cnn = null;
      QueueSender sender = null;
      QueueSession session = null;
      InitialContext ctx = new InitialContext();
      Queue queue = (Queue) ctx.lookup("queue/tutorial/example");
      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
      try {
         cnn = factory.createQueueConnection();
         session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
  
         TextMessage msg = session.createTextMessage("Hello World");
   
         msg.setStringProperty("to", to);
         msg.setStringProperty("from", from);
         msg.setStringProperty("subject", subject);
         sender = session.createSender(queue);
         sender.send(msg);
         System.out.println("Message sent successfully to remote queue.");
      } finally {
         // Cleanup
         // close the connection
         if (cnn != null)
         {
            cnn.close();
         }
      }
}
 
開發者ID:nyla-solutions,項目名稱:nyla,代碼行數:36,代碼來源:EmailMDBTest.java

示例12: testTempQueueDelete

import javax.jms.QueueSender; //導入方法依賴的package包/類
@Test
public void testTempQueueDelete() throws Exception {
   connection.start();
   QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   TemporaryQueue tempQueue = queueSession.createTemporaryQueue();

   ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
   try {
      QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueSender queueSender = newQueueSession.createSender(tempQueue);

      Message msg = queueSession.createMessage();
      queueSender.send(msg);

      try {
         QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
         fail("should have gotten exception but got consumer: " + consumer);
      } catch (JMSException ex) {
         //correct
      }

      connection.close();

      try {
         Message newMsg = newQueueSession.createMessage();
         queueSender.send(newMsg);
      } catch (JMSException e) {
         //ok
      }

   } finally {
      newConn.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:36,代碼來源:SimpleOpenWireTest.java

示例13: sendAMessage

import javax.jms.QueueSender; //導入方法依賴的package包/類
public void sendAMessage(String msg) throws JMSException {

        QueueSender send = session.createSender(que);
        TextMessage tm = session.createTextMessage(msg);

        send.send(tm);
        send.close();
    }
 
開發者ID:OpenRAP,項目名稱:jboss6-jms-chat,代碼行數:9,代碼來源:SendJMSMessage.java

示例14: doExecuteRequest

import javax.jms.QueueSender; //導入方法依賴的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 {
		if (jms11Available) {
			// Standard JMS 1.1 API usage...
			responseQueue = session.createTemporaryQueue();
			producer = session.createProducer(queue);
			consumer = session.createConsumer(responseQueue);
			requestMessage.setJMSReplyTo(responseQueue);
			producer.send(requestMessage);
		}
		else {
			// Perform all calls on QueueSession reference for JMS 1.0.2 compatibility...
			// DEPRECATED but kept around with the deprecated JmsTemplate102 etc classes for the time being.
			QueueSession queueSession = (QueueSession) session;
			responseQueue = queueSession.createTemporaryQueue();
			QueueSender sender = queueSession.createSender(queue);
			producer = sender;
			consumer = queueSession.createReceiver(responseQueue);
			requestMessage.setJMSReplyTo(responseQueue);
			sender.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();
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:47,代碼來源:JmsInvokerClientInterceptor.java

示例15: run

import javax.jms.QueueSender; //導入方法依賴的package包/類
@Override
public void run()
   {
       super.run();
       
       try
       {
           QueueSender sender = getSession().createSender(queue);
           
           startSynchro.waitFor();
           
           for (int n = 0 ; n < messageCount ; n++)
           {
               variableWait();
               
               int msgPriority = (priority != -1) ? priority : random.nextInt(10);
               
               Message message = msgFactory.createDummyMessage(messageSize);
               sender.send(message, deliveryMode, msgPriority, timeToLive);
               if (transacted)
                   getSession().commit();
           }
           
           sender.close();
           //System.out.println(getName()+" thread complete ("+messageCount+" messages sent)");
       }
       catch (Throwable e)
       {
           inError = true;
           e.printStackTrace();
       }
   }
 
開發者ID:timewalker74,項目名稱:ffmq,代碼行數:33,代碼來源:QueueSenderThread.java


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