Java tutorial
/* * Copyright 1999-2016 feidee.com All right reserved. This software is the * confidential and proprietary information of feidee.com ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with feidee.com. */ package lpp.rabbitmq.original; import java.io.IOException; import java.util.concurrent.TimeoutException; import org.apache.commons.lang.SerializationUtils; import com.rabbitmq.client.Consumer; import com.rabbitmq.client.Envelope; import com.rabbitmq.client.ShutdownSignalException; /** * ?? * @author lipanpan * @time 2016224 */ public class QueueConsumer extends EndPoint implements Runnable, Consumer { public QueueConsumer(String endpointName, RabbitMqConfig config) throws IOException, TimeoutException { super(endpointName, config); } public void run() { try { // (thiscallback an interface to the consumer object) // push???? // start consuming messages. Auto acknowledge messages. channel.basicConsume(endPointName, true, this); // channel.basicGet(queue, autoAck)//?Pull? } catch (IOException e) { e.printStackTrace(); } } /** * Called when consumer is registered. */ public void handleConsumeOk(String consumerTag) { System.out.println("Consumer " + consumerTag + " registered"); } public void handleCancel(String consumerTag) { } public void handleCancelOk(String consumerTag) { } public void handleRecoverOk(String consumerTag) { } public void handleShutdownSignal(String consumerTag, ShutdownSignalException arg1) { } public void handleDelivery(String arg0, Envelope arg1, com.rabbitmq.client.AMQP.BasicProperties arg2, byte[] arg3) throws IOException { OMessage msg = (OMessage) SerializationUtils.deserialize(arg3); System.out.println(msg.toString()); } }