本文整理汇总了Java中javax.jms.QueueConnectionFactory.createQueueConnection方法的典型用法代码示例。如果您正苦于以下问题:Java QueueConnectionFactory.createQueueConnection方法的具体用法?Java QueueConnectionFactory.createQueueConnection怎么用?Java QueueConnectionFactory.createQueueConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.QueueConnectionFactory
的用法示例。
在下文中一共展示了QueueConnectionFactory.createQueueConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSpecificConsumerRetrieval
import javax.jms.QueueConnectionFactory; //导入方法依赖的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();
}
示例2: getQueueConnection
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public QueueConnection getQueueConnection(QueueConnectionFactory qcf)
throws JMSException {
final QueueConnection qc;
final String username = Config.parms.getString("us");
if (username != null && username.length() != 0) {
Log.logger.log(Level.INFO, "getQueueConnection(): authenticating as \"" + username + "\"");
final String password = Config.parms.getString("pw");
qc = qcf.createQueueConnection(username, password);
} else {
qc = qcf.createQueueConnection();
}
return qc;
}
示例3: initializeQueue
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
private void initializeQueue() {
Context context = null;
try {
context = new InitialContext();
final QueueConnectionFactory factory = (QueueConnectionFactory) context.lookup(QUEUE_FACTORY_NAME);
queueConnection = factory.createQueueConnection();
queueConnection.start();
final Queue queue = (Queue) context.lookup(QUEUE_NAME);
session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createSender(queue);
sender.setDeliveryMode(DeliveryMode.PERSISTENT);
} catch (NamingException | JMSException e) {
throw new IWSException(IWSErrors.ERROR, "Queue sender (NotificationEmailSender) initialization failed.", e);
} finally {
close(context);
}
}
示例4: acknowledge
import javax.jms.QueueConnectionFactory; //导入方法依赖的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();
}
}
示例5: setupJMS
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public void setupJMS() throws NamingException, JMSException {
InitialContext iniCtx;
if (this.isClustered()) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "Clustered - Using HA-JMS");
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
p.put(Context.PROVIDER_URL, "localhost:1100"); // HA-JNDI port.
iniCtx = new InitialContext(p);
} else {
Logger.getLogger(getClass().getName()).log(Level.INFO, "Not clustered - Using non-HA JMS");
iniCtx = new InitialContext();
}
QueueConnectionFactory qcf = (QueueConnectionFactory) iniCtx.lookup("ConnectionFactory");
queue = (javax.jms.Queue) iniCtx.lookup("queue/acsQueue");
conn = qcf.createQueueConnection();
conn.setExceptionListener(this);
conn.start();
queuesession = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
producer = queuesession.createProducer(queue);
clear();
}
示例6: openConnection
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
/**
* The method overrides the one in the super class to perform
* JMS specific functions.
*/
@Override
protected Object openConnection() throws ConnectionException {
qConnection = null;
qSession = null;
queue = null;
try {
String server_url = this.getAttributeValueSmart(SERVER_URL);
if ("THIS_SERVER".equals(server_url)) server_url = null;
String queue_name = this.getQueueName();
JMSServices jmsServices = JMSServices.getInstance();
QueueConnectionFactory qFactory = jmsServices.getQueueConnectionFactory(server_url);
qConnection = qFactory.createQueueConnection();
qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
qConnection.start();
queue = jmsServices.getQueue(qSession, queue_name);
} catch (Exception e) {
logger.severeException("Exception in JmsAdapter.openConnection()" , e);
throw new ConnectionException(ConnectionException.CONNECTION_DOWN, "Exception in invoking JmsAdapter" , e);
}
return qSession;
}
示例7: sendMessage
import javax.jms.QueueConnectionFactory; //导入方法依赖的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();
}
}
示例8: ReorderRequestMessageListener
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public ReorderRequestMessageListener() {
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
InitialContext ctx = new InitialContext(properties);
// Lookup connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
QueueConnection queueConnection = connFactory.createQueueConnection();
queueConnection.start();
QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
//Receive message
Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
MessageConsumer consumer = queueSession.createConsumer(queue);
consumer.setMessageListener(this);
} catch (NamingException | JMSException e) {
e.printStackTrace();
}
}
示例9: ReorderResponseMessageListener
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public ReorderResponseMessageListener() {
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
properties.put("queue."+ REORDER_RESPONSE_QUEUE, REORDER_RESPONSE_QUEUE);
InitialContext ctx = new InitialContext(properties);
// Lookup connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
queueConnection = connFactory.createQueueConnection();
queueConnection.start();
queueSession =
queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
//Receive message
Queue queue = (Queue) ctx.lookup(REORDER_RESPONSE_QUEUE);
MessageConsumer consumer = queueSession.createConsumer(queue);
consumer.setMessageListener(this);
} catch (NamingException | JMSException e) {
e.printStackTrace();
}
}
示例10: sendMessage
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public static void sendMessage(Order order) throws NamingException, JMSException {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
InitialContext ctx = new InitialContext(properties);
// Lookup connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
queueConnection = connFactory.createQueueConnection();
queueConnection.start();
queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
// Send message
Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
// create the message to send
ObjectMessage message = queueSession.createObjectMessage(order);
javax.jms.QueueSender queueSender = queueSession.createSender(queue);
queueSender.send(message);
queueSender.close();
queueSession.close();
queueConnection.close();
}
示例11: inicializaConsumidorJMS
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
/**
* Inicializa configura��es do recebedor de mensagens JMS
* @throws ValidadorException
*
* @throws NamingException
* @throws JMSException
*/
public void inicializaConsumidorJMS(String proxy, DllDadosDTO configuracaoDll) throws BaseValidadorException {
try {
if (!isInicializado()) {
// seta a configuracao da dll.
messageListener.setConfiguracaoDll(configuracaoDll);
// recupera initialContext conectado ao ActiveMQ
InitialContext initialContext = getInitialContext(proxy);
connectionFactory = (QueueConnectionFactory) initialContext.lookup(getJmsConectionFactory());
connection = connectionFactory.createQueueConnection();
session = createQueueSession(connection);
aQueue = (Queue) initialContext.lookup(getJmsRequestQueue());
queueReceiver = session.createReceiver(aQueue);
queueReceiver.setMessageListener(messageListener);
connection.start();
}
inicializado = true;
} catch (Exception e) {
throw new ValidadorException("Erro ao tentar inicializar consumidor JMS!", e);
}
}
示例12: setupConnection
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public void setupConnection() throws JMSException, NamingException {
Properties properties1 = new Properties();
properties1.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
properties1.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext iniCtx = new InitialContext(properties1);
Object tmp = iniCtx.lookup("ConnectionFactory");
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
conn = qcf.createQueueConnection();
que = (Queue) iniCtx.lookup("queue/questionqueue");
session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
conn.start();
System.out.println("Connection Started");
}
示例13: QueueMessageSender
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public QueueMessageSender(String jndiFactory, String jndiQueue)
throws NamingException, JMSException {
// gets the JNDI
Context context = new InitialContext();
// gets a ConnectionFactory
QueueConnectionFactory queueFactory = (QueueConnectionFactory) context
.lookup(jndiFactory);
// create a JMS connection from the ConnectionFactory
queueConnection = queueFactory.createQueueConnection();
// creates the session with JMS, the first param specifies whether or not the session is transactional
// if true the messages only will be send after a commit()
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// gets the JMS destination
queue = (Queue) context.lookup(jndiQueue);
// gets the sender to JMS destination
queueSender = queueSession.createSender(queue);
}
示例14: QueueMessageSender
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public QueueMessageSender(String jndiFactory, String jndiQueue)
throws NamingException, JMSException {
// gets the JNDI
Context context = new InitialContext();
// gets a ConnectionFactory
QueueConnectionFactory queueFactory = (QueueConnectionFactory) context
.lookup(jndiFactory);
// create a JMS connection from the ConnectionFactory
queueConnection = queueFactory.createQueueConnection();
// creates the session with JMS
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
// gets the JMS destination
queue = (Queue) context.lookup(jndiQueue);
// gets the sender to JMS destination
queueSender = queueSession.createSender(queue);
}
示例15: createQueue
import javax.jms.QueueConnectionFactory; //导入方法依赖的package包/类
public static Queue createQueue(String uri, String queueName) throws JMSException {
QueueConnectionFactory connectionFactory = null;
QueueConnection connection = null;
QueueSession session = null;
Queue queue = null;
try {
connectionFactory = new ActiveMQConnectionFactory(uri);
connection = connectionFactory.createQueueConnection();
connection.start();
session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
queue = session.createQueue(queueName);
session.commit();
} finally {
closeQuietly(session);
closeQuietly(connection);
}
return queue;
}