List of usage examples for javax.jms Session createProducer
MessageProducer createProducer(Destination destination) throws JMSException;
From source file:com.tremolosecurity.provisioning.util.PooledMessageProducerFactory.java
@Override public PooledObject<MessageProducerHolder> makeObject() throws Exception { Connection con = prov.getQueueConnection(); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = session.createQueue(taskQueueName); MessageProducer mp = session.createProducer(q); return new DefaultPooledObject(new MessageProducerHolder(con, mp, session)); }
From source file:com.nesscomputing.jms.activemq.ServiceDiscoveryTransportFactoryTest.java
private void sendTestMessage(final Connection directConnection) throws Exception { final Session session = directConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageProducer producer = session.createProducer(session.createQueue(QNAME)); producer.send(session.createTextMessage(uniqueId)); session.close();/*from ww w . j av a2 s .c o m*/ }
From source file:com.mdmserver.managers.ControllerFacade.java
public void lockPhone(int accountId) throws IOException { Account account = databaseManager.getAccountByAccountId(accountId); Context ctx;/*from w w w .j av a 2 s. c o m*/ try { ctx = new InitialContext(); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/mdmConnectionFactory"); Queue queue = (Queue) ctx.lookup("jms/mdmQueue"); MessageProducer messageProducer; System.out.println("Naming success"); try { javax.jms.Connection connection = connectionFactory.createConnection(); javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); messageProducer = session.createProducer(queue); TextMessage message = session.createTextMessage(); message.setStringProperty(Account.FIELD_NAME_CLOUD_ID, account.getCloudId()); ControlClient cClient = new ControlClient(); cClient.setCommandType(ControlClient.LOCK_PHONE_CONTROL); Gson gson = new Gson(); message.setStringProperty(ControlClient.CONTROL_CLIENT_KEY, gson.toJson(cClient)); System.out.println("It come from Servlet:" + message.getText()); messageProducer.send(message); System.out.println("JMS success"); } catch (JMSException ex) { // Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex); System.out.println("JMS exception"); } } catch (NamingException ex) { // Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex); System.out.println("Naming exception"); } }
From source file:com.mdmserver.managers.ControllerFacade.java
public void uninstallApp(int accountId, String appPackageName) { Account account = databaseManager.getAccountByAccountId(accountId); Context ctx;//from w w w .j a v a2 s.co m try { ctx = new InitialContext(); ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("jms/mdmConnectionFactory"); Queue queue = (Queue) ctx.lookup("jms/mdmQueue"); MessageProducer messageProducer; System.out.println("Naming success"); try { javax.jms.Connection connection = connectionFactory.createConnection(); javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); messageProducer = session.createProducer(queue); TextMessage message = session.createTextMessage(); message.setStringProperty(Account.FIELD_NAME_CLOUD_ID, account.getCloudId()); ControlClient cClient = new ControlClient(); cClient.setCommandType(ControlClient.UNINSTALL_APP_CONTROL); cClient.setJsonCommandDetails(appPackageName); Gson gson = new Gson(); message.setStringProperty(ControlClient.CONTROL_CLIENT_KEY, gson.toJson(cClient)); System.out.println("It come from Servlet:" + message.getText()); messageProducer.send(message); System.out.println("JMS success"); } catch (JMSException ex) { // Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex); System.out.println("JMS exception"); } } catch (NamingException ex) { // Logger.getLogger(Control.class.getName()).log(Level.SEVERE, null, ex); System.out.println("Naming exception"); } }
From source file:org.fusesource.stompjms.JmsTestSupport.java
protected void sendMessages(Session session, Destination destination, int count) throws JMSException { MessageProducer producer = session.createProducer(destination); for (int i = 0; i < count; i++) { producer.send(session.createTextMessage(messageTextPrefix + i)); }/* www .j a va2 s . c o m*/ producer.close(); }
From source file:org.soitoolkit.commons.studio.components.logger.impl.DefaultLogEventSender.java
protected void sendOneTextMessage(Session session, String queueName, String message) { MessageProducer publisher = null;//from ww w. j a v a 2 s . co m try { publisher = session.createProducer(session.createQueue(queueName)); TextMessage textMessage = session.createTextMessage(message); publisher.send(textMessage); } catch (JMSException e) { throw new RuntimeException(e); } finally { try { if (publisher != null) publisher.close(); } catch (JMSException e) { } } }
From source file:org.apache.axis2.transport.jms.MockEchoEndpoint.java
@Setup @SuppressWarnings("unused") private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception { Destination destination = channel.getDestination(); Destination replyDestination = channel.getReplyDestination(); connection = env.getConnectionFactory().createConnection(); connection.setExceptionListener(this); connection.start();/*from w w w .ja v a2 s. c om*/ replyConnection = env.getConnectionFactory().createConnection(); replyConnection.setExceptionListener(this); final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); final MessageProducer producer = replySession.createProducer(replyDestination); MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE) .createConsumer(destination); consumer.setMessageListener(new MessageListener() { public void onMessage(Message message) { try { log.info("Message received: ID = " + message.getJMSMessageID()); Message reply; if (message instanceof BytesMessage) { reply = replySession.createBytesMessage(); IOUtils.copy(new BytesMessageInputStream((BytesMessage) message), new BytesMessageOutputStream((BytesMessage) reply)); } else if (message instanceof TextMessage) { reply = replySession.createTextMessage(); ((TextMessage) reply).setText(((TextMessage) message).getText()); } else { // TODO throw new UnsupportedOperationException("Unsupported message type"); } reply.setJMSCorrelationID(message.getJMSMessageID()); reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE)); producer.send(reply); log.info("Message sent: ID = " + reply.getJMSMessageID()); } catch (Throwable ex) { fireEndpointError(ex); } } }); }
From source file:org.jboss.processFlow.knowledgeService.AsyncBAMProducerPool.java
BAMProducerWrapper(Session sessionObj, Destination dQueue) throws JMSException { this.sessionObj = sessionObj; this.producerObj = sessionObj.createProducer(dQueue); this.producerObj.setDeliveryMode(DeliveryMode.PERSISTENT); }
From source file:org.apache.activemq.bugs.VMTransportClosureTest.java
/** * This test demonstrates how the "disposeOnDisonnect" feature of * VMTransportServer can incorrectly close all VM connections to the local * broker.//from ww w.j a v a 2s.co m */ public void testPrematureClosure() throws Exception { // Open a persistent connection to the local broker. The persistent // connection is maintained through the test and should prevent the // VMTransportServer from stopping itself when the local transport is // closed. ActiveMQConnection persistentConn = (ActiveMQConnection) createConnection(); persistentConn.start(); Session session = persistentConn.createSession(true, Session.SESSION_TRANSACTED); MessageProducer producer = session.createProducer(destination); for (int i = 0; i < NUM_ATTEMPTS; i++) { LOG.info("Attempt: " + i); // Open and close a local transport connection. As is done by by // most users of the transport, ensure that the transport is stopped // when closed by the peer (via ShutdownInfo). Closing the local // transport should not affect the persistent connection. final Transport localTransport = TransportFactory.connect(broker.getVmConnectorURI()); localTransport.setTransportListener(new TransportListener() { public void onCommand(Object command) { if (command instanceof ShutdownInfo) { try { localTransport.stop(); } catch (Exception ex) { throw new RuntimeException(ex); } } } public void onException(IOException error) { // ignore } public void transportInterupted() { // ignore } public void transportResumed() { // ignore } }); localTransport.start(); localTransport.stop(); // Ensure that the persistent connection is still usable. producer.send(session.createMessage()); session.rollback(); } persistentConn.close(); }
From source file:org.apache.activemq.camel.JmsJdbcXARollbackTest.java
private void sendJMSMessageToKickOffRoute() throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA"); factory.setWatchTopicAdvisories(false); Connection connection = factory.createConnection(); connection.start();//w ww . j ava 2s . c o m Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(new ActiveMQQueue("scp_transacted")); TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++); message.setJMSCorrelationID("pleaseCorrelate"); producer.send(message); connection.close(); }