Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathWorkerProcess.java
More file actions
Latest commit
35 lines (29 loc) · 1.08 KB
/
Copy pathWorkerProcess.java
File metadata and controls
35 lines (29 loc) · 1.08 KB
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
importcom.rabbitmq.client.*;
importjava.io.IOException;
publicclassWorkerProcess {
privatefinalstaticStringQUEUE_NAME = "hello";
publicstaticvoidmain(String[] argv) throwsException {
Stringuri = System.getenv("CLOUDAMQP_URL");
if (uri == null)
uri = "amqp://guest:guest@localhost";
ConnectionFactoryfactory = newConnectionFactory();
factory.setUri(uri);
factory.setConnectionTimeout(30000);
Connectionconnection = factory.newConnection();
Channelchannel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" [*] Waiting for messages");
DefaultConsumerconsumer = newDefaultConsumer(channel) {
@Override
publicvoidhandleDelivery(StringconsumerTag,
Envelopeenvelope,
AMQP.BasicPropertiesproperties,
byte[] body)
throwsIOException {
Stringmessage = newString(body);
System.out.println(" [x] Received '" + message + "'");
}
};
channel.basicConsume(QUEUE_NAME, true, consumer);
}
}