Ai
1 Star 0 Fork 0

shark爱吃辣椒/MessageQueue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DemoProducer.java 1.13 KB
一键复制 编辑 原始数据 按行查看 历史
package com.example.mq.demo;
import com.example.mq.mqclient.Channel;
import com.example.mq.mqclient.Connection;
import com.example.mq.mqclient.ConnectionFactory;
import com.example.mq.mqserver.core.ExchangeType;
import java.io.IOException;
/*
* 这个类用来表示一个生产者.
* 通常这是一个单独的服务器程序.
*/
public class DemoProducer {
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("生产者");
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("127.0.0.1");
factory.setPort(9090);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare("test", ExchangeType.DIRECT, false, false, null);
channel.queueDeclare("test", false, false, false, null);
byte[] message = "hello2222".getBytes();
boolean b = channel.basicPublish("test", "test", null, message);
System.out.println("消息投递完成! ok=" + b);
Thread.sleep(500);
channel.close();
connection.close();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zouzh00/message-queue.git
git@gitee.com:zouzh00/message-queue.git
zouzh00
message-queue
MessageQueue
master

搜索帮助