Tabnine Logo
ConnectionFactory
Code IndexAdd Tabnine to your IDE (free)

How to use
ConnectionFactory
in
javax.jms

Best Java code snippets using javax.jms.ConnectionFactory (Showing top 20 results out of 2,277)

Refine searchRefine arrow

  • Connection
  • Session
  • MessageProducer
  • MessageConsumer
  • TextMessage
origin: kiegroup/jbpm

MessageProducer producer = null;
try {
  queueConnection = connectionFactory.createConnection();
  queueSession = queueConnection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
  TextMessage message = queueSession.createTextMessage(eventXml);
  message.setStringProperty("LogType", "Task");
  producer = queueSession.createProducer(queue);  
  producer.setPriority(priority);
  producer.send(message);
} catch (Exception e) {
  throw new RuntimeException("Error when sending JMS message with working memory event", e);
  if (producer != null) {
    try {
      producer.close();
    } catch (JMSException e) {
      logger.warn("Error when closing producer", e);
      queueSession.close();
    } catch (JMSException e) {
      logger.warn("Error when closing queue session", e);
      queueConnection.close();
    } catch (JMSException e) {
      logger.warn("Error when closing queue connection", e);
origin: spring-projects/spring-framework

@Override
public JMSContext createContext(String userName, String password) {
  return obtainTargetConnectionFactory().createContext(userName, password);
}
origin: apache/activemq-artemis

@Test
public void testCreateProducerOnNullQueue() throws Exception {
 Connection conn = getConnectionFactory().createConnection();
 Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 Message m = sess.createTextMessage("something");
 MessageProducer p = sess.createProducer(null);
 p.send(queue1, m);
 MessageConsumer c = sess.createConsumer(queue1);
 conn.start();
 // receiveNoWait is not guaranteed to return message immediately
 TextMessage rm = (TextMessage) c.receive(1000);
 ProxyAssertSupport.assertEquals("something", rm.getText());
 conn.close();
}
origin: mercyblitz/segmentfault-lessons

private static void receiveMessage() throws Exception {
  // 创建 ActiveMQ 链接,设置 Broker URL
  ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
  // 创造 JMS 链接
  Connection connection = connectionFactory.createConnection();
  // 启动连接
  connection.start();
  // 创建会话 Session
  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  // 创建消息目的 - Queue 名称为 "TEST"
  Destination destination = session.createQueue("TEST");
  // 创建消息消费者
  MessageConsumer messageConsumer = session.createConsumer(destination);
  // 获取消息
  Message message = messageConsumer.receive(100);
  if (message instanceof TextMessage) {
    TextMessage textMessage = (TextMessage) message;
    System.out.println("消息消费内容:" + textMessage.getText());
  }
  // 关闭消息消费者
  messageConsumer.close();
  // 关闭会话
  session.close();
  // 关闭连接
  connection.stop();
  connection.close();
}
origin: apache/activemq-artemis

  @Test
  public void testCreateQueueTempQueue() throws Exception {
   conn = cf.createConnection();

   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   Queue tempQueue = session.createTemporaryQueue();

   String tempQueueName = tempQueue.getQueueName();

//      assertFalse(tempQueueName.startsWith(ActiveMQDestination.JMS_QUEUE_ADDRESS_PREFIX));

   Queue replyQueue = session.createQueue(tempQueueName);

   MessageProducer producer = session.createProducer(replyQueue);

   producer.send(session.createMessage());

   MessageConsumer consumer = session.createConsumer(replyQueue);

   conn.start();

   assertNotNull(consumer.receive(10000));
  }

origin: spring-projects/spring-framework

given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer);  // no MessageSelector...
given(session.getTransacted()).willReturn(false);
given(session.getAcknowledgeMode()).willReturn(Session.AUTO_ACKNOWLEDGE);
given(connection.createSession(this.container.isSessionTransacted(),
    this.container.getSessionAcknowledgeMode())).willReturn(session);
given(connectionFactory.createConnection()).willReturn(connection);
verify(connection).setExceptionListener(this.container);
verify(connection).start();
origin: mercyblitz/segmentfault-lessons

  private static void sendMessage() throws Exception {
    // 创建 ActiveMQ 链接,设置 Broker URL
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    // 创造 JMS 链接
    Connection connection = connectionFactory.createConnection();
    // 创建会话 Session
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // 创建消息目的 - Queue 名称为 "TEST"
    Destination destination = session.createQueue("TEST");
    // 创建消息生产者
    MessageProducer producer = session.createProducer(destination);
    // 创建消息 - 文本消息
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setText("Hello,World");
    // 发送文本消息
    producer.send(message);

    // 关闭消息生产者
    producer.close();
    // 关闭会话
    session.close();
    // 关闭连接
    connection.close();
  }
}
origin: kiegroup/jbpm

  public List<Message> receive(Queue queue) throws Exception {
    List<Message> messages = new ArrayList<Message>();
    
    Connection qconnetion = factory.createConnection();
    Session qsession = qconnetion.createSession(true, QueueSession.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = qsession.createConsumer(queue);
    qconnetion.start();
    
    Message m = null;
    
    while ((m = consumer.receiveNoWait()) != null) {
      messages.add(m);
    }
    consumer.close();            
    qsession.close();            
    qconnetion.close();
    
    return messages;
  }
}
origin: kiegroup/jbpm

void receiveAndProcess(Queue queue, EntityManagerFactory entityManagerFactory, long waitTime, int countDown) throws Exception {
  Connection qconnetion = factory.createConnection();
  Session qsession = qconnetion.createSession(true, QueueSession.AUTO_ACKNOWLEDGE);
  MessageConsumer consumer = qsession.createConsumer(queue);
  qconnetion.start();
  consumer.setMessageListener(rec);
  Assertions.assertThat(latch.await(waitTime, TimeUnit.MILLISECONDS)).isTrue();
  consumer.close();            
  qsession.close();            
  qconnetion.close();
origin: spring-projects/spring-framework

@Test
public void testDestroyClosesConsumersSessionsAndConnectionInThatOrder() throws Exception {
  MessageConsumer messageConsumer = mock(MessageConsumer.class);
  Session session = mock(Session.class);
  // Queue gets created in order to create MessageConsumer for that Destination...
  given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
  // and then the MessageConsumer gets created...
  given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer);  // no MessageSelector...
  Connection connection = mock(Connection.class);
  // session gets created in order to register MessageListener...
  given(connection.createSession(this.container.isSessionTransacted(),
      this.container.getSessionAcknowledgeMode())).willReturn(session);
  // and the connection is start()ed after the listener is registered...
  ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
  given(connectionFactory.createConnection()).willReturn(connection);
  this.container.setConnectionFactory(connectionFactory);
  this.container.setDestinationName(DESTINATION_NAME);
  this.container.setMessageListener(new TestMessageListener());
  this.container.afterPropertiesSet();
  this.container.start();
  this.container.destroy();
  verify(messageConsumer).close();
  verify(session).close();
  verify(connection).setExceptionListener(this.container);
  verify(connection).start();
  verify(connection).close();
}
origin: spring-projects/spring-framework

@Test
public void testTransactionCommitWithMessageProducer() throws JMSException {
  Destination dest = new StubQueue();
  ConnectionFactory cf = mock(ConnectionFactory.class);
  Connection con = mock(Connection.class);
  Session session = mock(Session.class);
  MessageProducer producer = mock(MessageProducer.class);
  final Message message = mock(Message.class);
  given(cf.createConnection()).willReturn(con);
  given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
  given(session.createProducer(dest)).willReturn(producer);
  given(session.getTransacted()).willReturn(true);
  JmsTransactionManager tm = new JmsTransactionManager(cf);
  TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
  JmsTemplate jt = new JmsTemplate(cf);
  jt.send(dest, new MessageCreator() {
    @Override
    public Message createMessage(Session session) throws JMSException {
      return message;
    }
  });
  tm.commit(ts);
  verify(producer).send(message);
  verify(session).commit();
  verify(producer).close();
  verify(session).close();
  verify(con).close();
}
origin: apache/activemq-artemis

public void sendMessage(SimpleString queue) throws Exception {
 ConnectionFactory fact = getCF();
 Connection connection = fact.createConnection();
 try {
   Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   connection.start();
   Destination destination = session.createQueue(queue.toString());
   MessageProducer producer = session.createProducer(destination);
   TextMessage message = session.createTextMessage();
   message.setText("Message");
   producer.send(message);
 } finally {
   connection.close();
 }
}
origin: apache/activemq-artemis

@Test
public void testAutoCreateOnDurableSubscribeToTopic() throws Exception {
 Connection connection = cf.createConnection();
 connection.setClientID("myClientID");
 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 javax.jms.Topic topic = ActiveMQJMSClient.createTopic(QUEUE_NAME);
 MessageConsumer consumer = session.createDurableConsumer(topic, "myDurableSub");
 MessageProducer producer = session.createProducer(topic);
 producer.send(session.createTextMessage("msg"));
 connection.start();
 assertNotNull(consumer.receive(500));
 connection.close();
 assertNotNull(server.getManagementService().getResource(ResourceNames.ADDRESS + "test"));
 assertNotNull(server.locateQueue(SimpleString.toSimpleString("myClientID.myDurableSub")));
}
origin: apache/activemq-artemis

private void checkDestination(String name) throws Exception {
 ConnectionFactory cf = (ConnectionFactory) namingContext.lookup("/someCF");
 Connection conn = cf.createConnection();
 Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 Destination dest = (Destination) namingContext.lookup(name);
 conn.start();
 MessageConsumer cons = sess.createConsumer(dest);
 MessageProducer prod = sess.createProducer(dest);
 prod.send(sess.createMessage());
 assertNotNull(cons.receiveNoWait());
 conn.close();
}
origin: spring-projects/spring-framework

Session nonTxSession = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
given(txSession.getTransacted()).willReturn(true);
given(con.createSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
session1.getTransacted();
session1.close();  // should lead to rollback
session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
session1.close();
origin: apache/storm

ConnectionFactory cf = jmsProvider.connectionFactory();
Destination dest = jmsProvider.destination();
this.connection = cf.createConnection();
this.session = connection.createSession(false, jmsAcknowledgeMode);
MessageConsumer consumer = session.createConsumer(dest);
consumer.setMessageListener(this);
this.connection.start();
origin: apache/activemq-artemis

@Test
public void testSharedDurableConsumer() throws Exception {
 conn = cf.createConnection();
 conn.start();
 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 topic = ActiveMQJMSClient.createTopic(T_NAME);
 MessageConsumer cons = session.createSharedDurableConsumer(topic, "test1");
 MessageProducer producer = session.createProducer(topic);
 producer.send(session.createTextMessage("test"));
 TextMessage txt = (TextMessage) cons.receive(5000);
 Assert.assertNotNull(txt);
}
origin: apache/activemq-artemis

@Test
public void testSharedConsumer() throws Exception {
 conn = cf.createConnection();
 conn.start();
 Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 topic = ActiveMQJMSClient.createTopic(T_NAME);
 MessageConsumer cons = session.createSharedConsumer(topic, "test1");
 MessageProducer producer = session.createProducer(topic);
 producer.send(session.createTextMessage("test"));
 TextMessage txt = (TextMessage) cons.receive(5000);
 Assert.assertNotNull(txt);
}
origin: apache/karaf

@Override
public Object execute() throws Exception {
  Connection connection = connectionFactory.createConnection();
  connection.start();
  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createQueue(queue);
  MessageProducer producer = session.createProducer(destination);
  TextMessage textMessage = session.createTextMessage(message);
  producer.send(textMessage);
  return null;
}
origin: apache/activemq-artemis

private void receiveJMS(int nMsgs, ConnectionFactory factory) throws JMSException {
 Connection connection2 = factory.createConnection();
 Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
 connection2.start();
 MessageConsumer consumer = session2.createConsumer(session2.createQueue(testQueueName));
 for (int i = 0; i < nMsgs; i++) {
   Message message = consumer.receive(5000);
   Assert.assertNotNull(message);
   Assert.assertEquals(i, message.getIntProperty("i"));
 }
 connection2.close();
}
javax.jmsConnectionFactory

Javadoc

A ConnectionFactory object encapsulates a set of connection configuration parameters that has been defined by an administrator. A client uses it to create a connection with a JMS provider.

A ConnectionFactory object is a JMS administered object and supports concurrent use.

JMS administered objects are objects containing configuration information that are created by an administrator and later used by JMS clients. They make it practical to administer the JMS API in the enterprise.

Although the interfaces for administered objects do not explicitly depend on the Java Naming and Directory Interface (JNDI) API, the JMS API establishes the convention that JMS clients find administered objects by looking them up in a JNDI namespace.

An administrator can place an administered object anywhere in a namespace. The JMS API does not define a naming policy.

It is expected that JMS providers will provide the tools an administrator needs to create and configure administered objects in a JNDI namespace. JMS provider implementations of administered objects should be both javax.jndi.Referenceable and java.io.Serializable so that they can be stored in all JNDI naming contexts. In addition, it is recommended that these implementations follow the JavaBeansTM design patterns.

This strategy provides several benefits:

  • It hides provider-specific details from JMS clients.
  • It abstracts administrative information into objects in the Java programming language ("Java objects") that are easily organized and administered from a common management console.
  • Since there will be JNDI providers for all popular naming services, this means that JMS providers can deliver one implementation of administered objects that will run everywhere.

An administered object should not hold on to any remote resources. Its lookup should not use remote resources other than those used by the JNDI API itself.

Clients should think of administered objects as local Java objects. Looking them up should not have any hidden side effects or use surprising amounts of local resources.

Most used methods

  • createConnection
    Creates a connection with the specified user identity. The connection is created in stopped mode. No
  • createContext
    Creates a JMSContext with the specified user identity and the specified session mode. A connection a
  • <init>
  • setProperty
  • toString

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • putExtra (Intent)
  • getSupportFragmentManager (FragmentActivity)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • BufferedInputStream (java.io)
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the i
  • Socket (java.net)
    Provides a client-side TCP socket.
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • ServletException (javax.servlet)
    Defines a general exception a servlet can throw when it encounters difficulty.
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now