FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rabbitmq-tutorials/java/EmitLogTopic.java at main · rabbitmq/rabbitmq-tutorials · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
rabbitmq
/
rabbitmq-tutorials
Public
Notifications
You must be signed in to change notification settings
Fork
3.5k
Star
6.9k
Code
Issues
3
Pull requests
1
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
rabbitmq-tutorials
/
java
/
EmitLogTopic.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (39 loc) · 1.66 KB
Breadcrumbs
rabbitmq-tutorials
/
java
/
EmitLogTopic.java
Copy path
File metadata and controls
49 lines (39 loc) · 1.66 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import
com
.
rabbitmq
.
client
.
BuiltinExchangeType
;
import
com
.
rabbitmq
.
client
.
Channel
;
import
com
.
rabbitmq
.
client
.
Connection
;
import
com
.
rabbitmq
.
client
.
ConnectionFactory
;
public
class
EmitLogTopic
{
private
static
final
String
EXCHANGE_NAME
=
"topic_logs"
;
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
ConnectionFactory
factory
=
new
ConnectionFactory
();
factory
.
setHost
(
"localhost"
);
try
(
Connection
connection
=
factory
.
newConnection
();
Channel
channel
=
connection
.
createChannel
()) {
channel
.
exchangeDeclare
(
EXCHANGE_NAME
,
BuiltinExchangeType
.
TOPIC
);
String
routingKey
=
getRouting
(
argv
);
String
message
=
getMessage
(
argv
);
channel
.
basicPublish
(
EXCHANGE_NAME
,
routingKey
,
null
,
message
.
getBytes
(
"UTF-8"
));
System
.
out
.
println
(
" [x] Sent '"
+
routingKey
+
"':'"
+
message
+
"'"
);
}
}
private
static
String
getRouting
(
String
[]
strings
) {
if
(
strings
.
length
<
1
)
return
"anonymous.info"
;
return
strings
[
0
];
}
private
static
String
getMessage
(
String
[]
strings
) {
if
(
strings
.
length
<
2
)
return
"Hello World!"
;
return
joinStrings
(
strings
,
" "
,
1
);
}
private
static
String
joinStrings
(
String
[]
strings
,
String
delimiter
,
int
startIndex
) {
int
length
=
strings
.
length
;
if
(
length
==
0
)
return
""
;
if
(
length
<
startIndex
)
return
""
;
StringBuilder
words
=
new
StringBuilder
(
strings
[
startIndex
]);
for
(
int
i
=
startIndex
+
1
;
i
<
length
;
i
++) {
words
.
append
(
delimiter
).
append
(
strings
[
i
]);
}
return
words
.
toString
();
}
}
Back
|
FazBrowse Home
|
New Git URL