更新记录
1.0.2(2024-08-12)
添加息屏保活
1.0.1(2024-08-10)
解决主动关闭连接还会自动重连问题
1.0.0(2024-08-10)
插件初次上传
查看更多
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.21,Android:4.4,iOS:不确定,HarmonyNext:不确定 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
使用说明
下载试用本插件后,请重新打包自定义基座
如果使用该插件,请删除自己引入的 amqp-client 相关 jar 包,避免打包自定义基座 class 冲突
该插件使用 rabbitMQ 官方 amqp-client(AMQP 协议)连接 rabbitMQ 服务端,可以发送消息到队列、发送消息到交换机、也可以通过订阅实现订阅模式、路由模式、主题模式等
该插件实现了连接断开后自动重连,每 5 秒尝试进行重连,重连后自动订阅连接丢失前的订阅
rabbitMQ 官网文档
有关于该插件的疑问或者技术探讨可以联系作者(备注来源)
wx 号:z1003975792y
API 介绍
1、连接函数 connect
参数 |
类型 |
必填 |
备注 |
option |
object |
是 |
连接参数 |
复制代码import { connect } from '@/uni_modules/zy-rabbitmq'
let option = {
host: '10.10.xx.xx',
port: 5672,
userName: 'xxxx',
password: 'xxxx',
virtualHost: '/',
success: (code) => {},
fail: (code, msg) => {},
keepAlive: false,
notificationContentText,
notificationContentTitle,
}
connect(option)
2、发布消息到队列函数 publish
参数 |
类型 |
必填 |
备注 |
option |
object |
是 |
参数 |
复制代码import { publish } from '@/uni_modules/zy-rabbitmq'
var message = { a: 1, b: 2 }
let option = {
queueName: 'xxxx',
message: JSON.stringify(message),
durable: false,
exclusive: false,
autoDelete: false,
channelKeep: false,
success: (code) => {},
fail: (code, msg) => {},
}
publish(option)
3、发布消息到交换机函数 publishToExchange
参数 |
类型 |
必填 |
备注 |
option |
object |
是 |
参数 |
复制代码import { publishToExchange } from '@/uni_modules/zy-rabbitmq'
var message = { a: 1, b: 2 }
let option = {
exchange: 'xxxx',
exchangeType: 'topic',
routingKey: 'xx.xx',
message: JSON.stringify(message),
durable: false,
autoDelete: false,
channelKeep: false,
success: (code) => {},
fail: (code, msg) => {},
}
publishToExchange(option)
4、订阅函数 subscribe
参数 |
类型 |
必填 |
备注 |
option |
object |
是 |
参数 |
复制代码import { subscribe } from '@/uni_modules/zy-rabbitmq'
let option = {
exchange: 'xxxx',
exchangeType: 'topic',
routingKey: 'xx.xx',
message: JSON.stringify(message),
durable: false,
autoDelete: false,
callback: (res) => {},
fail: (code, msg) => {},
}
let consumerTag = subscribe(option)
5、取消订阅函数 unsubscribe
参数 |
类型 |
必填 |
备注 |
consumerTag |
string |
是 |
消费者的唯一标识 |
(code, msg)=>{} |
function |
是 |
取消订阅的回调 |
复制代码import { unsubscribe } from '@/uni_modules/zy-rabbitmq'
unsubscribe(consumerTag, (code, msg) => {
console.log(code, msg)
})
6、监听连接丢失函数 onLostConnect
参数 |
类型 |
必填 |
备注 |
(res)=>{code, msg} |
function |
是 |
连接丢失的回调函数 |
复制代码import { onLostConnect } from '@/uni_modules/zy-rabbitmq'
onLostConnect((code, msg) => {
console.log(code, msg)
})
7、监听连接恢复函数 onRecovery
默认在连接丢失的情况下会自动重连,该函数是监听连接恢复状态的回调函数
参数 |
类型 |
必填 |
备注 |
(res)=>{code, msg} |
function |
是 |
连接恢复的回调函数 |
复制代码import { onRecovery } from '@/uni_modules/zy-rabbitmq'
onRecovery((code, msg) => {
console.log(code, msg)
})
8、关闭连接函数 closeConnect
参数 |
类型 |
必填 |
备注 |
(res)=>{code} |
function |
是 |
关闭连接的回调函数 |
复制代码import { closeConnect } from '@/uni_modules/zy-rabbitmq'
closeConnect((code) => {
console.log(code)
})