Skip to content

Commit e1f5cb0

Browse files
author
Emile Joubert
committed
Merge remote branch 'origin/bug23558'
2 parents 2ff33f9 + 34052d0 commit e1f5cb0

File tree

10 files changed

+101
-16
lines changed

10 files changed

+101
-16
lines changed

dotnet/Receive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ static void Main(string[] args) {
1010
IConnection connection = factory.CreateConnection();
1111
IModel channel = connection.CreateModel();
1212

13-
channel.QueueDeclare("test");
13+
channel.QueueDeclare("hello");
1414

1515
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
16-
channel.BasicConsume("test", true, null, consumer);
16+
channel.BasicConsume("hello", true, null, consumer);
1717

1818
Console.WriteLine(" [*] Waiting for messages. To exit press CTRL+C");
1919
while(true) {

dotnet/Send.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ static void Main(string[] args) {
99
IConnection connection = factory.CreateConnection();
1010
IModel channel = connection.CreateModel();
1111

12-
channel.QueueDeclare("test");
12+
channel.QueueDeclare("hello");
1313

1414
string message = "Hello World!";
1515
byte[] body = System.Text.Encoding.UTF8.GetBytes(message);
1616

17-
channel.BasicPublish("", "test", null, body);
17+
channel.BasicPublish("", "hello", null, body);
1818
Console.WriteLine(" [x] Sent {0}", message);
1919

2020
channel.Close();

java/Recv.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public static void main(String[] argv) {
1010
try {
1111
conn = new ConnectionFactory().newConnection();
1212
Channel chan = conn.createChannel();
13-
chan.queueDeclare("test", false, false, false, null);
13+
chan.queueDeclare("hello", false, false, false, null);
1414
QueueingConsumer consumer = new QueueingConsumer(chan);
15-
chan.basicConsume("test", true, consumer);
15+
chan.basicConsume("hello", true, consumer);
1616
while (true) {
1717
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
1818
System.out.println(new String(delivery.getBody()));

java/Send.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public static void main(String[] argv) {
1010
try {
1111
conn = new ConnectionFactory().newConnection();
1212
Channel chan = conn.createChannel();
13-
chan.queueDeclare("test", false, false, false, null);
14-
chan.basicPublish("", "test", null, "Hello World!".getBytes());
13+
chan.queueDeclare("hello", false, false, false, null);
14+
chan.basicPublish("", "hello", null, "Hello World!".getBytes());
1515
}
1616
finally {
1717
if (conn != null) conn.close();

php/receive.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
$channel = $connection->channel();
77

88

9-
$channel->queue_declare('test', false, false, false, false);
9+
$channel->queue_declare('hello', false, false, false, false);
1010

1111
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
1212

1313
$callback = function($msg) {
1414
echo " [x] Received ", $msg->body, "\n";
1515
};
1616

17-
$channel->basic_consume('test', '', false, true, false, false, $callback);
17+
$channel->basic_consume('hello', '', false, true, false, false, $callback);
1818

1919
while(count($channel->callbacks)) {
2020
$channel->wait();

php/send.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
$channel = $connection->channel();
77

88

9-
$channel->queue_declare('test', false, false, false, false);
9+
$channel->queue_declare('hello', false, false, false, false);
1010

1111
$msg = new AMQPMessage('Hello World!');
12-
$channel->basic_publish($msg, '', 'test');
12+
$channel->basic_publish($msg, '', 'hello');
1313

1414
echo " [x] Sent 'Hello World!'\n";
1515

python/receive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
channel = connection.channel()
88

99

10-
channel.queue_declare(queue='test')
10+
channel.queue_declare(queue='hello')
1111

1212
print ' [*] Waiting for messages. To exit press CTRL+C'
1313

1414
def callback(ch, method, header, body):
1515
print " [x] Received %r" % (body,)
1616

1717
channel.basic_consume(callback,
18-
queue='test',
18+
queue='hello',
1919
no_ack=True)
2020

2121
pika.asyncore_loop()

python/rpc_client.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
import pika
3+
import uuid
4+
5+
class FibonacciClient(object):
6+
def __init__(self):
7+
self.connection = pika.AsyncoreConnection(pika.ConnectionParameters(
8+
host='127.0.0.1',
9+
credentials=pika.PlainCredentials('guest', 'guest')))
10+
self.channel = self.connection.channel()
11+
12+
result = self.channel.queue_declare(auto_delete=True)
13+
self.callback_queue = result.queue
14+
15+
self.requests = {}
16+
self.channel.basic_consume(self.on_response, no_ack=True,
17+
queue=self.callback_queue)
18+
19+
def on_response(self, ch, method, props, body):
20+
corr_id = props.correlation_id
21+
if corr_id in self.requests:
22+
self.requests[corr_id] = body
23+
24+
def call(self, n):
25+
corr_id = str(uuid.uuid4())
26+
self.requests[corr_id] = None
27+
self.channel.basic_publish(exchange='',
28+
routing_key='rpc_queue',
29+
properties=pika.BasicProperties(
30+
reply_to = self.callback_queue,
31+
correlation_id = corr_id,
32+
),
33+
body=str(n))
34+
while self.requests[corr_id] is None:
35+
pika.asyncore_loop(count=1)
36+
response = self.requests[corr_id]
37+
del self.requests[corr_id]
38+
return int(response)
39+
40+
41+
fibonacci_rpc = FibonacciClient()
42+
43+
print " [x] Requesting fib(30)"
44+
response = fibonacci_rpc.call(30)
45+
print " [.] Got %r" % (response,)
46+

python/rpc_server.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
import pika
3+
4+
5+
connection = pika.AsyncoreConnection(pika.ConnectionParameters(
6+
host='127.0.0.1',
7+
credentials=pika.PlainCredentials('guest', 'guest')))
8+
channel = connection.channel()
9+
10+
11+
channel.queue_declare(queue='rpc_queue')
12+
13+
14+
def fib(n):
15+
if n == 0:
16+
return 0
17+
elif n == 1:
18+
return 1
19+
else:
20+
return fib(n-1) + fib(n-2)
21+
22+
def on_request(ch, method, props, body):
23+
n = int(body)
24+
25+
print " [.] fib(%s)" % (n,)
26+
response = fib(n)
27+
28+
ch.basic_publish(exchange='',
29+
routing_key=props.reply_to,
30+
properties=pika.BasicProperties(correlation_id = \
31+
props.correlation_id),
32+
body=str(response))
33+
ch.basic_ack(delivery_tag = method.delivery_tag)
34+
35+
channel.basic_qos(prefetch_count=1)
36+
channel.basic_consume(on_request, queue='rpc_queue')
37+
38+
print " [x] Awaiting RPC requests"
39+
pika.asyncore_loop()

python/send.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
channel = connection.channel()
88

99

10-
channel.queue_declare(queue='test')
10+
channel.queue_declare(queue='hello')
1111

1212
channel.basic_publish(exchange='',
13-
routing_key='test',
13+
routing_key='hello',
1414
body='Hello World!')
1515
print " [x] Sent 'Hello World!'"
1616
connection.close()

0 commit comments

Comments
 (0)