Skip to content

Commit af8fa62

Browse files
author
sergitoda
committed
Default Broker connection added
1 parent f371476 commit af8fa62

4 files changed

Lines changed: 31 additions & 6 deletions

File tree

pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
</dependencies>
6969
<build>
7070
<sourceDirectory>src</sourceDirectory>
71-
<testSourceDirectory>test</testSourceDirectory>
71+
<!-- <testSourceDirectory>test</testSourceDirectory> -->
7272
<resources>
7373
<resource>
7474
<directory>src/main/resources</directory>
@@ -108,7 +108,7 @@
108108
<manifest>
109109
<addClasspath>true</addClasspath>
110110
</manifest>
111-
</archive>
111+
</archive>
112112
</configuration>
113113
</plugin>
114114
<plugin>
@@ -117,6 +117,9 @@
117117
<version>2.14.1</version>
118118
<configuration>
119119
<skipTests>true</skipTests>
120+
<excludes>
121+
<exclude>omq/test/*</exclude>
122+
</excludes>
120123
</configuration>
121124
</plugin>
122125
</plugins>

src/main/java/omq/common/broker/Broker.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@ public class Broker {
5151
private Map<String, Object> proxies = new Hashtable<String, Object>();
5252
private Map<String, Object> multiProxies = new Hashtable<String, Object>();
5353

54+
public Broker() throws Exception {
55+
Properties env = new Properties();
56+
57+
remoteObjs = new HashMap<String, RemoteObject>();
58+
serializer = new Serializer(env);
59+
environment = env;
60+
connection = OmqConnectionFactory.getNewConnection(env);
61+
channel = connection.createChannel();
62+
addFaultTolerance();
63+
if (!connection.isOpen() || !channel.isOpen()) {
64+
if (connection.isOpen()) {
65+
connection.close();
66+
}
67+
throw new InitBrokerException("The connection didn't work");
68+
}
69+
}
70+
5471
public Broker(Properties env) throws Exception {
5572
// Load log4j configuration
5673
// URL log4jResource = Broker.class.getResource("/log4j.xml");

src/main/java/omq/common/util/OmqConnectionFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public static Connection getNewWorkingConnection(Properties env) throws Exceptio
8282
*/
8383
public static Connection getNewConnection(Properties env) throws IOException, KeyManagementException, NoSuchAlgorithmException {
8484
// Get login info of rabbitmq
85-
String username = env.getProperty(ParameterQueue.USER_NAME);
86-
String password = env.getProperty(ParameterQueue.USER_PASS);
85+
String username = env.getProperty(ParameterQueue.USER_NAME, ParameterQueue.DEFAULT_USER);
86+
String password = env.getProperty(ParameterQueue.USER_PASS, ParameterQueue.DEFAULT_PASS);
8787

8888
// Get host info of rabbimq (where it is)
89-
String host = env.getProperty(ParameterQueue.RABBIT_HOST);
90-
int port = Integer.parseInt(env.getProperty(ParameterQueue.RABBIT_PORT));
89+
String host = env.getProperty(ParameterQueue.RABBIT_HOST, ParameterQueue.DEFAULT_RABBIT_HOST);
90+
int port = Integer.parseInt(env.getProperty(ParameterQueue.RABBIT_PORT, ParameterQueue.DEFAULT_PORT));
9191

9292
boolean ssl = Boolean.parseBoolean(env.getProperty(ParameterQueue.ENABLE_SSL, "false"));
9393

src/main/java/omq/common/util/ParameterQueue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,9 @@ public class ParameterQueue {
141141
*/
142142
public static long DEFAULT_TIMEOUT = 1 * 1000 * 60;
143143

144+
public static String DEFAULT_USER = "guest";
145+
public static String DEFAULT_PASS = "guest";
146+
public static String DEFAULT_RABBIT_HOST = "localhost";
147+
public static String DEFAULT_PORT = "5672";
148+
144149
}

0 commit comments

Comments
 (0)