Giter Site home page Giter Site logo

Comments (6)

DrmagicE avatar DrmagicE commented on May 27, 2024 1

Oh, my fault.. Payload is a function .Try fmt.Println("Payload", string(msg.Payload())) @darlandieterich

from gmqtt.

DrmagicE avatar DrmagicE commented on May 27, 2024

You can either use the OnMsgArrived hook or implement a plugin.Here is some examples:

  1. Using hook: https://github.com/DrmagicE/gmqtt/blob/v0.1.3/examples/hook/main.go#L76
  2. Using plugin: #24 (comment)

from gmqtt.

darlandieterich avatar darlandieterich commented on May 27, 2024

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.

DrmagicE avatar DrmagicE commented on May 27, 2024

fmt.Println("Payload", string(msg.Payload))

from gmqtt.

darlandieterich avatar darlandieterich commented on May 27, 2024

well, I tried this before, but show error on compile:
cannot convert msg.Payload (type func() []byte) to type string

from gmqtt.

darlandieterich avatar darlandieterich commented on May 27, 2024

now this run so charm 👍

from gmqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.