package quantisan.qte_lmax;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class OrderObserver implements Runnable {
    final static Logger logger = LoggerFactory.getLogger(OrderObserver.class);
    private final Channel channel;
    private final QueueingConsumer consumer;

    public OrderObserver(Channel channel, QueueingConsumer consumer) {
        this.channel = channel;
        this.consumer = consumer;
    }

    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            QueueingConsumer.Delivery delivery = null;
            try {
                delivery = consumer.nextDelivery();
            } catch (InterruptedException e) {
                logger.error("Interrupted before order delivery.", e);
            }
            Order order = new Order(new String(delivery.getBody()));
            order.execute();
            logger.info("Received order '{}'", order);
            try {
                channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
            } catch (IOException e) {
                logger.error("Fail to acknowledge order message.", e);
            }
        }
    }
}

@@ -22,16 +22,45 @@
 _lmax;%0A%0A
+import com.lmax.api.Session;%0A
 import c
@@ -426,16 +426,51 @@
 onsumer;
+%0A    private final Session session;
 %0A%0A    pu
@@ -488,16 +488,33 @@
 bserver(
+Session session, 
 Channel 
@@ -547,24 +547,56 @@
 consumer) %7B%0A
+        this.session = session;%0A
         this
@@ -1045,16 +1045,25 @@
 w Order(
+session, 
 new Stri

order observer holds sessions