Commit 0ea78a83 authored by 's avatar
Browse files

ça a l'air bien parti, mais ils arrivent pas à communiquer entre eux... NB :...

ça a l'air bien parti, mais ils arrivent pas à communiquer entre eux... NB : en python2, il faut commenter les lignes où je split le body sur les guillemets, en python3, faut les garder
parent 9bbdc320
......@@ -32,32 +32,41 @@ class LamportClient:
self.queue = list();
self.times = {n:0 for n in range(1,clients+1)}
self.mustFree = False
self.mustRequest = True
self.channel = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost')
).channel()
self.channel.basic_qos(prefetch_count=1)
self.channel.exchange_declare(exchange="lamport", exchange_type="fanout")
self.channel.exchange_declare(exchange="lamport_init", exchange_type="fanout")
self.channel.exchange_declare(
exchange="lamport", exchange_type="fanout")
self.channel.exchange_declare(
exchange="lamport_init", exchange_type="fanout")
self.reception = self.channel.queue_declare(exclusive=True).method.queue
self.init_reception = self.channel.queue_declare(exclusive=True).method.queue
self.reception = self.channel.queue_declare(
exclusive=True).method.queue
self.init_reception = self.channel.queue_declare(
exclusive=True).method.queue
self.channel.queue_bind(exchange = "lamport", queue = self.reception)
self.channel.queue_bind(exchange = "lamport_init", queue = self.init_reception)
self.mustFree = False
self.mustRequest = True
self.channel.queue_bind(
exchange = "lamport", queue = self.reception)
self.channel.queue_bind(
exchange = "lamport_init", queue = self.init_reception)
def run(self):
print("I am {} of {} sites".format(self.id, len(list(self.times.keys()))))
print("I am {} of {} sites".format(
self.id, len(list(self.times.keys()))))
if self.channel.connection.is_open:
print("Well connected to server")
self.channel.basic_consume(self.initializeCycle, self.init_reception)
self.channel.basic_consume(
self.initializeCycle, self.init_reception)
self.channel.basic_publish(exchange="lamport_init", body = "{} says : Hello World!".format(self.id), routing_key='')
self.channel.basic_publish(
exchange="lamport_init", body = "{} says : Hello World!".format(self.id), routing_key='')
print("saying hello to the world")
self.channel.start_consuming()
......@@ -82,7 +91,7 @@ class LamportClient:
#client.free()
def initializeCycle(self, channel, method, properties, body):
_,body,_ = str(body).split("'")
#_,body,_ = str(body).split("'")
arrival_id = int(body.split(" ")[0])
self.n_clients_here += 1
......@@ -143,7 +152,7 @@ class LamportClient:
def when_receive(self, channel, method, properties, body):
body = str(body)
_,body,_ = body.split("'")
#_,body,_ = body.split("'")
print("received {}".format(body))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment