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
No related branches found
No related tags found
1 merge request!1Obj serialize
......@@ -22,7 +22,6 @@ import ch.hepia.model.House;
public class Client {
private static int ackMode;
private static String clientQueueName;
private static String messageBrokerUrl;
private boolean transacted = false;
......@@ -30,13 +29,15 @@ public class Client {
private Optional<MessageProducer> maybeProducer;
static {
messageBrokerUrl = "tcp://localhost:61616";
clientQueueName = "client.messages";
ackMode = Session.AUTO_ACKNOWLEDGE;
}
public Client() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(messageBrokerUrl);
public Client(final String ipBroker) {
final String brokerUrl = "tcp://" + ipBroker + ":61616";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
try {
Connection connection = connectionFactory.createConnection();
connection.start();
......@@ -103,7 +104,7 @@ public class Client {
}
public static void main(String[] args) {
Client c = new Client();
Client c = new Client( args.length == 1 ? args[0] : "localhost" );
c.send("COUCOU");
ArrayList<String> names = new ArrayList<>();
......
......@@ -6,19 +6,19 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
public class Server {
private static String messageBrokerUrl = "tcp://localhost:61616";
public Server() {
public Server(String ipBroker) {
try {
//This message broker is embedded
BrokerService broker = new BrokerService();
final String brokerUrl = "tcp://" + ipBroker + ":61616";
final BrokerService broker = new BrokerService();
broker.setPersistent(false);
broker.setUseJmx(false);
broker.addConnector(messageBrokerUrl);
broker.addConnector(brokerUrl);
broker.start();
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(messageBrokerUrl);
Connection connection = connectionFactory.createConnection();
final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl);
final Connection connection = connectionFactory.createConnection();
connection.start();
} catch (Exception e) {
......@@ -27,6 +27,8 @@ public class Server {
}
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