当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionFactory.createContext方法代码示例

本文整理汇总了Java中javax.jms.ConnectionFactory.createContext方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory.createContext方法的具体用法?Java ConnectionFactory.createContext怎么用?Java ConnectionFactory.createContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.createContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMessage

import javax.jms.ConnectionFactory; //导入方法依赖的package包/类
public void sendMessage(ConnectionFactory factory, Queue queue, String message) {
	try (JMSContext context = factory.createContext()) {

		context.createProducer().send(queue, message);

	} catch (JMSRuntimeException e) {
		logger.log(SEVERE, "error messaging", e);
	}
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:10,代码来源:SimpleClient.java

示例2: testListener

import javax.jms.ConnectionFactory; //导入方法依赖的package包/类
@Test
@RunAsClient
public void testListener() throws JMSException, NamingException, InterruptedException {
	final Properties env = new Properties();
	env.put(INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
	env.put(PROVIDER_URL, "http-remoting://127.0.0.1:8080");

	Context namingContext = new InitialContext(env);

	ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
	logger.info("Got ConnectionFactory " + CONNECTION_FACTORY);

	Destination destination = (Destination) namingContext.lookup(REMOTE_QUEUE_LOOKUP);
	logger.info("Got JMS Endpoint " + REMOTE_QUEUE_LOOKUP);

	String question = "how many components in your family?";
	String response = "they are four";

	// Create the JMS context
	JMSContext context = connectionFactory.createContext(USER_NAME, USER_PASSWORD);
	Questionary questionary = new Questionary();
	questionary.setQuestion(question);
	questionary.setResponse(response);
	assertFalse("questionary is not approved", questionary.isApproved());
	JMSProducer producer = context.createProducer();
	producer.send(destination, questionary);

	JMSConsumer consumer = context.createConsumer(destination);
	MessageQueueListener messageQueueListener = new MessageQueueListener();
	consumer.setMessageListener(messageQueueListener);
	sleep(100);
	questionary = messageQueueListener.getQuestionary();
	assertEquals("the question is: ", question, questionary.getQuestion());
	assertEquals("the response is: ", response, questionary.getResponse());
	assertTrue("the message is approved: ", questionary.isApproved());
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:37,代码来源:RemoteTestCase.java

示例3: consumeMessages

import javax.jms.ConnectionFactory; //导入方法依赖的package包/类
private List<String> consumeMessages(ConnectionFactory cf, String queue) {
    try (JMSContext ctx = cf.createContext()) {
        return consumeMessages(ctx, ctx.createQueue(queue));
    }
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.transx,代码行数:6,代码来源:ActiveMQTest.java


注:本文中的javax.jms.ConnectionFactory.createContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。