Skip to content
Snippets Groups Projects
Commit adf17100 authored by Joel Cavat's avatar Joel Cavat
Browse files

Could add broker ip address

parent 49063cac
Branches
No related tags found
1 merge request!1Obj serialize
...@@ -22,7 +22,6 @@ import ch.hepia.model.House; ...@@ -22,7 +22,6 @@ import ch.hepia.model.House;
public class Client { public class Client {
private static int ackMode; private static int ackMode;
private static String clientQueueName; private static String clientQueueName;
private static String messageBrokerUrl;
private boolean transacted = false; private boolean transacted = false;
...@@ -30,13 +29,15 @@ public class Client { ...@@ -30,13 +29,15 @@ public class Client {
private Optional<MessageProducer> maybeProducer; private Optional<MessageProducer> maybeProducer;
static { static {
messageBrokerUrl = "tcp://localhost:61616";
clientQueueName = "client.messages"; clientQueueName = "client.messages";
ackMode = Session.AUTO_ACKNOWLEDGE; ackMode = Session.AUTO_ACKNOWLEDGE;
} }
public Client() { public Client(final String ipBroker) {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(messageBrokerUrl);
final String brokerUrl = "tcp://" + ipBroker + ":61616";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
try { try {
Connection connection = connectionFactory.createConnection(); Connection connection = connectionFactory.createConnection();
connection.start(); connection.start();
...@@ -103,7 +104,7 @@ public class Client { ...@@ -103,7 +104,7 @@ public class Client {
} }
public static void main(String[] args) { public static void main(String[] args) {
Client c = new Client(); Client c = new Client( args.length == 1 ? args[0] : "localhost" );
c.send("COUCOU"); c.send("COUCOU");
ArrayList<String> names = new ArrayList<>(); ArrayList<String> names = new ArrayList<>();
......
...@@ -6,19 +6,19 @@ import org.apache.activemq.ActiveMQConnectionFactory; ...@@ -6,19 +6,19 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
public class Server { public class Server {
private static String messageBrokerUrl = "tcp://localhost:61616";
public Server() { public Server(String ipBroker) {
try { try {
//This message broker is embedded final String brokerUrl = "tcp://" + ipBroker + ":61616";
BrokerService broker = new BrokerService(); final BrokerService broker = new BrokerService();
broker.setPersistent(false); broker.setPersistent(false);
broker.setUseJmx(false); broker.setUseJmx(false);
broker.addConnector(messageBrokerUrl); broker.addConnector(brokerUrl);
broker.start(); broker.start();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(messageBrokerUrl); final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
Connection connection = connectionFactory.createConnection(); final Connection connection = connectionFactory.createConnection();
connection.start(); connection.start();
} catch (Exception e) { } catch (Exception e) {
...@@ -27,6 +27,8 @@ public class Server { ...@@ -27,6 +27,8 @@ public class Server {
} }
public static void main(String[] args) { public static void main(String[] args) {
new Server(); System.out.println(args[0]);
new Server( args.length == 1 ? args[0] : "localhost");
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment