Comments (6)
Oh, my fault.. Payload
is a function .Try fmt.Println("Payload", string(msg.Payload()))
@darlandieterich
from gmqtt.
You can either use the OnMsgArrived
hook or implement a plugin.Here is some examples:
- Using hook: https://github.com/DrmagicE/gmqtt/blob/v0.1.3/examples/hook/main.go#L76
- Using plugin: #24 (comment)
from gmqtt.
Hi!
Ok, then, how intercept the message in string?
OnMsgArrived: func(ctx context.Context, client gmqtt.Client, msg packets.Message) (valid bool) {
fmt.Println(msg) ///&{false 0 false /test/hello 0 [116 101 115 116 97 110 100 111 111 111 32 111 117 116 114 111 32 118 97 108 111 114 32 49 52 58 48 57 58 52 57 40 53 57 57 41]}
fmt.Println("Topic", msg.Topic)
fmt.Println("Payload", msg.Payload)
//Only qos1 & qos0 are acceptable(will be delivered)
if msg.Qos() == packets.QOS_2 {
return false
}
return true
},
tnks
from gmqtt.
fmt.Println("Payload", string(msg.Payload))
from gmqtt.
well, I tried this before, but show error on compile:
cannot convert msg.Payload (type func() []byte) to type string
from gmqtt.
now this run so charm
from gmqtt.
Related Issues (20)
- can not start HOT 1
- 单节点启动,出现too many open files问题 HOT 7
- last will & testament doesn't support binary payloads
- how to deploy gmqtt distributed cluster in k8s enviroment?
- Any benchmark test data? HOT 2
- 有没有推荐的golang版本的mqtt客户端和gmqtt一起工作?或者gmqtt有没有计划处一个自己的client库? HOT 1
- Memory leak using OnBasicAuthWrapper Hook HOT 7
- websocket packet size over 1024 causing read hang HOT 1
- grpc publish retain 标志不起作用
- 1000客户端压测报错/gmqtt/persistence/queue/mem/mem.go:185 +0x118 HOT 1
- 三节点的集群,客户端发送消费二进制数据,节点挂掉了 HOT 2
- 可能存在内存泄漏 HOT 2
- panic: persistence factory: memory not found? HOT 1
- Modify topic before publishing
- 关于mqtts的问题 HOT 2
- Alternatives or sucessor of this project
- Old Docker Image
- 有时候存在消息未送达的情况
- 哪里空了啊
- 插件hook函数加载时间点优先于日志
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmqtt.