本文整理了Java中org.apache.activemq.ActiveMQConnectionFactory.<init>()
方法的一些代码示例,展示了ActiveMQConnectionFactory.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ActiveMQConnectionFactory.<init>()
方法的具体详情如下:
包路径:org.apache.activemq.ActiveMQConnectionFactory
类名称:ActiveMQConnectionFactory
方法名:<init>
暂无
代码示例来源:origin: apache/activemq
/**
* A static helper method to create a new connection
*
* @return an ActiveMQConnection
* @throws JMSException
*/
public static ActiveMQConnection makeConnection() throws JMSException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
return (ActiveMQConnection)factory.createConnection();
}
代码示例来源:origin: apache/activemq
ActiveMQDestination dest = destination.getActiveMQDestination();
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerUrl);
Connection connection = null;
try {
connection = cf.createConnection(userName, password);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage msg = (ActiveMQTextMessage) session.createTextMessage(body);
producer.send(msg);
connection.close();
代码示例来源:origin: apache/activemq
@Before
public void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.start();
factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
producerConnection = factory.createConnection();
producerConnection.start();
producerSession = producerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
queue = producerSession.createQueue(getClass().getName());
producer = producerSession.createProducer(queue);
}
代码示例来源:origin: stackoverflow.com
try {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection conn = factory.createConnection(user, password);
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer("test");
MessageConsumer consumer = session.createConsumer("test");
consumer.setMessageListener(this); // class that implements MessageListener
conn.start();
TextMessage message = new ActiveMQTextMessage();
message.setText("TestMessage");
producer.send(message);
} catch (JMSException e) {
// somethings very wrong
}
代码示例来源:origin: apache/activemq
@Test(timeout = 60000)
public void testStealLinkFails() throws Exception {
final String clientID = "ThisIsAClientId";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(unstealableConnectionURI);
Connection connection1 = factory.createConnection();
connection1.setClientID(clientID);
connection1.start();
try {
Connection connection2 = factory.createConnection();
connection2.setClientID(clientID);
connection2.start();
fail("Should not have been able to steal the link.");
} catch (InvalidClientIDException e) {
LOG.info("Caught expected error on trying to steal link: {}", e.getMessage());
LOG.trace("Error: ", e);
}
}
代码示例来源:origin: cn-cerc/summer-mis
public QueueConnection() throws JMSException {
// 创建一个链接工厂
connectionFactory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKEN_URL);
// 从工厂中创建一个链接
connection = connectionFactory.createConnection();
// 开启链接
connection.start();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
}
代码示例来源:origin: org.chtijbug.drools/drools-platform-runtime-javase
private void initJmsConnection() throws JMSException {
String url = "tcp://" + this.platformServer + ":" + this.platformPort;
ConnectionFactory factory = new ActiveMQConnectionFactory(url);
try {
Connection connection = factory.createConnection();
session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(this.platformQueueName);
producer = session.createProducer(queue);
} catch (JMSException exp) {
// TODO handle properly exception
exp.printStackTrace();
}
}
代码示例来源:origin: apache/activemq
@Before
public void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.setUseJmx(true);
String connectionUri = brokerService.addConnector("tcp://localhost:0").getPublishableConnectString();
brokerService.start();
brokerService.waitUntilStarted();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri);
final Connection conn = connectionFactory.createConnection();
try {
conn.start();
final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Destination queue = session.createQueue(testQueueName);
final Message toSend = session.createMessage();
toSend.setStringProperty("foo", "bar");
final MessageProducer producer = session.createProducer(queue);
producer.send(queue, toSend);
} finally {
conn.close();
}
}
代码示例来源:origin: apache/activemq
@Override
protected void setUp() throws Exception {
brokerService = new BrokerService();
brokerService.setPersistent(false);
brokerService.start();
factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
consumerConnection = factory.createConnection();
consumerConnection.start();
producerConnection = factory.createConnection();
producerConnection.start();
consumerSession = consumerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
topic = consumerSession.createTopic(getName());
producerSession = producerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE);
consumer = consumerSession.createConsumer(topic);
producer = producerSession.createProducer(topic);
}
代码示例来源:origin: stackoverflow.com
@Test
public void test() throws Exception {
final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"vm://localhost?broker.persistent=false");
final Connection connection = connectionFactory.createConnection();
connection.start();
final Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
final Queue queue = session.createTemporaryQueue();
{
final MessageProducer producer = session.createProducer(queue);
final TextMessage message = session.createTextMessage("testing");
producer.send(message);
}
{
final MessageConsumer consumer = session.createConsumer(queue);
final TextMessage message = (TextMessage) consumer.receiveNoWait();
Assert.assertNotNull(message);
Assert.assertEquals("testing", message.getText());
}
}
代码示例来源:origin: apache/activemq
@Test(timeout = 60000)
public void testStealLinkSuccess() throws Exception {
final String clientID = "ThisIsAClientId";
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(stealableConnectionURI);
Connection connection1 = factory.createConnection();
connection1.setClientID(clientID);
connection1.start();
Connection connection2 = factory.createConnection();
connection2.setClientID(clientID);
connection2.start();
} catch (InvalidClientIDException e) {
LOG.info("Should not have failed while stealing the link: {}", e.getMessage());
代码示例来源:origin: activequant/aq2o
/**
* constructs and in-memory active mq transport factory.
*
* @throws Exception
*/
public ActiveMQTransportFactory() throws Exception {
String conUrl = "vm://localhost";
log.info("Constructing embedded ActiveMQTransportFactory for " + conUrl);
connectionFactory = new ActiveMQConnectionFactory(conUrl);
connectionFactory.setProducerWindowSize(1024000);
connection = connectionFactory.createTopicConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
代码示例来源:origin: apache/activemq
/**
* A static helper method to create a new connection
*
* @param uri
* @return and ActiveMQConnection
* @throws JMSException
*/
public static ActiveMQConnection makeConnection(String uri) throws JMSException, URISyntaxException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri);
return (ActiveMQConnection)factory.createConnection();
}
代码示例来源:origin: javahongxi/whatsmars
public static void main(String[] args) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("TEST.QUEUE");
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
for (int i= 0; i < 100; i++) {
TextMessage message = session.createTextMessage("hello world! " + i);
producer.send(message);
System.out.println(message);
}
producer.close();
}
}
代码示例来源:origin: javahongxi/whatsmars
public static void main(String[] args) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("TEST.QUEUE");
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
System.out.println(message);
}
});
connection.start();
}
}
代码示例来源:origin: stackoverflow.com
String url = "tcp://localhost:61616";
BrokerService broker = new BrokerService();
broker.addConnector(url);
broker.start();
ConnectionFactory cf = new ActiveMQConnectionFactory(url);
Connection conn = cf.createConnection();
Session s = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
ActiveMQQueue q = new ActiveMQQueue("test");
MessageProducer p = s.createProducer(q);
p.send(s.createTextMessage("!!!!"), DeliveryMode.NON_PERSISTENT, 0, 1000); // ttl = 1s
Thread.sleep(2000);
MessageConsumer c = s.createConsumer(q);
System.out.println("Received: " + c.receiveNoWait());
System.exit(1);
代码示例来源:origin: apache/activemq
@Test
public void testAMQ5050DefaultHost() throws Exception {
// Let verify a host header is added to the connection.
Connection connection = new ActiveMQConnectionFactory(brokerConnectURI).createConnection();
connection.start();
CopyOnWriteArrayList<TransportConnection> connections = broker.getConnectorByName("tcp").getConnections();
assertEquals(1, connections.size());
assertNotNull(connections.get(0).getRemoteWireFormatInfo().getHost());
connection.stop();
}
代码示例来源:origin: apache/oozie
@Before
protected void setUp() throws Exception {
super.setUp();
services = super.setupServicesForHCatalog();
services.init();
connFac = new ActiveMQConnectionFactory(localActiveMQBroker);
conn = connFac.createConnection();
conn.start();
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
代码示例来源:origin: apache/activemq
/**
* A static helper method to create a new connection
*
* @param user
* @param password
* @param uri
* @return an ActiveMQConnection
* @throws JMSException
*/
public static ActiveMQConnection makeConnection(String user, String password, String uri) throws JMSException, URISyntaxException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(user, password, new URI(uri));
return (ActiveMQConnection)factory.createConnection();
}
代码示例来源: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();
}
}
内容来源于网络,如有侵权,请联系作者删除!