java操作rabbitmq接受消费消息示例代码

代码语言:java

所属分类:其他

代码描述:java操作rabbitmq接受消费消息示例代码

代码标签: java rabbitmq 接受 消费 消息 示例 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

import java.io.IOException;
import java.util.concurrent.TimeoutException;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Consumer;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.AMQP;

public class HelloWorld {
    private final static String QUEUE_NAME = "rabbitMQ_test2";

    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();

        //设置RabbitMQ地址
        factory.setHost("127.0.0.1");
        factory.setUsername("guest");
        factory.setPassword("guest");
        factory.setPort(5672);

        //创建一个新的连接
        Connection connection = factory.newConnection();

        //创建一个通道
        Channel channel = connection.createChannel();

        //声明要关注的队列
        channe.........完整代码请登录后点击上方下载按钮下载查看

网友评论0