5.3. 配置池
本例演示了设置连接和会话配置选项。
示例:配置池 - ConnectWithConfiguration.java
package net.example; import javax.jms.Connection; import javax.jms.ConnectionFactory; import org.apache.qpid.jms.JmsConnectionFactory; import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; public class ConnectWithConfiguration { public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: ConnectWithConfiguration <connection-uri>"); System.exit(1); } String connUri = args[0]; ConnectionFactory factory = new JmsConnectionFactory(connUri); JmsPoolConnectionFactory pool = new JmsPoolConnectionFactory(); try { pool.setConnectionFactory(factory); // Set the max connections per user to a higher value pool.setMaxConnections(5); // Create a MessageProducer for each createProducer() call pool.setUseAnonymousProducers(false); Connection conn = pool.createConnection(); conn.start(); try { System.out.println("CONNECT: Connected to '" + connUri + "'"); } finally { conn.close(); } } finally { pool.stop(); } } }