source: trunk/objectmq/src/omq/common/remote/OmqConnectionFactory.java @ 9

Last change on this file since 9 was 9, checked in by stoda, 12 years ago

First commit

File size: 1.2 KB
Line 
1package omq.common.remote;
2
3import java.io.IOException;
4import java.security.KeyManagementException;
5import java.security.NoSuchAlgorithmException;
6import java.util.Properties;
7
8import omq.common.util.ParameterQueue;
9
10
11import com.rabbitmq.client.Connection;
12import com.rabbitmq.client.ConnectionFactory;
13
14/**
15 *
16 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
17 *
18 */
19public class OmqConnectionFactory {
20        public static Connection getConnection(Properties env) throws IOException, KeyManagementException, NoSuchAlgorithmException {
21                // Get login info of rabbitmq
22                String username = env.getProperty(ParameterQueue.USER_NAME);
23                String password = env.getProperty(ParameterQueue.USER_PASS);
24
25                // Get host info of rabbimq (where it is)
26                String host = env.getProperty(ParameterQueue.SERVER_HOST);
27                int port = Integer.parseInt(env.getProperty(ParameterQueue.SERVER_PORT));
28
29                boolean ssl = Boolean.parseBoolean(env.getProperty(ParameterQueue.ENABLE_SSL));
30
31                // Start a new connection and channel
32                ConnectionFactory factory = new ConnectionFactory();
33                factory.setUsername(username);
34                factory.setPassword(password);
35                factory.setHost(host);
36                factory.setPort(port);
37                if (ssl) {
38                        factory.useSslProtocol();
39                }
40                return factory.newConnection();
41        }
42}
Note: See TracBrowser for help on using the repository browser.