package com.mobile263.ying.Rabbitmq;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.QueueingConsumer.Delivery;
import com.rabbitmq.client.ShutdownSignalException;
public class RabConsumer extends Endpoint implements Runnable{
QueueingConsumer consumer = null;
public RabConsumer(String endpointName) throws IOException, TimeoutException {
super(endpointName);
consumer = new QueueingConsumer(channel);
channel.basicConsume(endpointName, true, consumer);
}
public void run() {
while(true) {
try {
Delivery delivery = consumer.nextDelivery();
String recStr = new String(delivery.getBody());
System.out.println(recStr);
} catch (ShutdownSignalException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
RabConsumer consumer = new RabConsumer("yingQueue");
Thread thread1 = new Thread(consumer);
thread1.start();
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.QueueingConsumer.Delivery;
import com.rabbitmq.client.ShutdownSignalException;
public class RabConsumer extends Endpoint implements Runnable{
QueueingConsumer consumer = null;
public RabConsumer(String endpointName) throws IOException, TimeoutException {
super(endpointName);
consumer = new QueueingConsumer(channel);
channel.basicConsume(endpointName, true, consumer);
}
public void run() {
while(true) {
try {
Delivery delivery = consumer.nextDelivery();
String recStr = new String(delivery.getBody());
System.out.println(recStr);
} catch (ShutdownSignalException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
RabConsumer consumer = new RabConsumer("yingQueue");
Thread thread1 = new Thread(consumer);
thread1.start();
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
}
}
}