Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
topic-broker-example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
joel.cavat
topic-broker-example
Commits
adf17100
Commit
adf17100
authored
6 years ago
by
Joel Cavat
Browse files
Options
Downloads
Patches
Plain Diff
Could add broker ip address
parent
49063cac
Branches
Branches containing commit
No related tags found
1 merge request
!1
Obj serialize
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/communication/Client.java
+6
-5
6 additions, 5 deletions
src/main/java/ch/hepia/communication/Client.java
src/main/java/ch/hepia/communication/Server.java
+10
-8
10 additions, 8 deletions
src/main/java/ch/hepia/communication/Server.java
with
16 additions
and
13 deletions
src/main/java/ch/hepia/communication/Client.java
+
6
−
5
View file @
adf17100
...
@@ -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
<>();
...
...
This diff is collapsed.
Click to expand it.
src/main/java/ch/hepia/communication/Server.java
+
10
−
8
View file @
adf17100
...
@@ -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
(
messageB
rokerUrl
);
broker
.
addConnector
(
b
rokerUrl
);
broker
.
start
();
broker
.
start
();
ActiveMQConnectionFactory
connectionFactory
=
new
ActiveMQConnectionFactory
(
messageB
rokerUrl
);
final
ActiveMQConnectionFactory
connectionFactory
=
new
ActiveMQConnectionFactory
(
b
rokerUrl
);
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"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment