FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
rabbitmq-tutorials/java/RPCServer.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
/
RPCServer.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (44 loc) · 1.83 KB
Breadcrumbs
rabbitmq-tutorials
/
java
/
RPCServer.java
Copy path
File metadata and controls
55 lines (44 loc) · 1.83 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
49
50
51
52
53
54
55
import
com
.
rabbitmq
.
client
.*;
import
java
.
util
.
Map
;
public
class
RPCServer
{
private
static
final
String
RPC_QUEUE_NAME
=
"rpc_queue"
;
private
static
int
fib
(
int
n
) {
int
a
=
0
;
int
b
=
1
;
for
(
int
i
=
0
;
i
<
n
;
i
++) {
int
next
=
a
+
b
;
a
=
b
;
b
=
next
;
}
return
a
;
}
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
ConnectionFactory
factory
=
new
ConnectionFactory
();
factory
.
setHost
(
"localhost"
);
Connection
connection
=
factory
.
newConnection
();
Channel
channel
=
connection
.
createChannel
();
channel
.
queueDeclare
(
RPC_QUEUE_NAME
,
true
,
false
,
false
,
Map
.
of
(
"x-queue-type"
,
"quorum"
));
channel
.
queuePurge
(
RPC_QUEUE_NAME
);
channel
.
basicQos
(
1
);
System
.
out
.
println
(
" [x] Awaiting RPC requests"
);
DeliverCallback
deliverCallback
= (
consumerTag
,
delivery
) -> {
AMQP
.
BasicProperties
replyProps
=
new
AMQP
.
BasicProperties
.
Builder
()
.
correlationId
(
delivery
.
getProperties
().
getCorrelationId
())
.
build
();
String
response
=
""
;
try
{
String
message
=
new
String
(
delivery
.
getBody
(),
"UTF-8"
);
int
n
=
Integer
.
parseInt
(
message
);
System
.
out
.
println
(
" [.] fib("
+
message
+
")"
);
response
+=
fib
(
n
);
}
catch
(
RuntimeException
e
) {
System
.
out
.
println
(
" [.] "
+
e
);
}
finally
{
channel
.
basicPublish
(
""
,
delivery
.
getProperties
().
getReplyTo
(),
replyProps
,
response
.
getBytes
(
"UTF-8"
));
channel
.
basicAck
(
delivery
.
getEnvelope
().
getDeliveryTag
(),
false
);
}
};
channel
.
basicConsume
(
RPC_QUEUE_NAME
,
false
,
deliverCallback
, (
consumerTag
-> {}));
}
}
Back
|
FazBrowse Home
|
New Git URL