// RegisterMqttTopic is used to let a client register to a specific MQTT topic.
// This functions returns a nats subject the client can subscribe to in order to read the
// forwarded message.
RegisterMqttTopic is used to let a client register to a specific MQTT topic.
This functions returns a nats subject the client can subscribe to in order to read the
forwarded message.
// RegisterMqttTopic is used to let a client register to a specific MQTT topic . // This functions returns a nats subject the client can subscribe to in order to read the // forwarded message .
func (c *Client) RegisterMqttTopic(topic string) (schema.RegisterSubResponseType, error) {
	msg := make(map[string]interface{})
	msg["topic"] = topic
	registerSubRequestCodec, err := goavro.NewCodec(schema.RegisterSubRequest)
	if err != nil {
		return schema.RegisterSubResponseType{}, err
	}
	bytes, err := avro.Writer(msg, registerSubRequestCodec)
	if err != nil {
		return schema.RegisterSubResponseType{}, err
	}
	response, err := c.nats.Request(fmt.Sprintf("%s.config.register", c.target), bytes, 2*time.Second)
	if err != nil {
		if c.nats.LastError() != nil {
			return schema.RegisterSubResponseType{}, fmt.Errorf("%v for request", c.nats.LastError())
		}
		return schema.RegisterSubResponseType{}, err
	}
	avro, _ := avro.NewReader(response.Data)
	j, _ := avro.ByteString()
	res := schema.RegisterSubResponseType{}
	err = json.Unmarshal(j, &res)
	if err != nil {
		return schema.RegisterSubResponseType{}, err
	}
	if len(res.Error) > 0 {
		return schema.RegisterSubResponseType{}, fmt.Errorf("%s", res.Error)
	}
	return res, nil
}
func ( c * Client ) RegisterMqttTopic ( topic string ) ( schema . RegisterSubResponseType , error ) { msg := make ( map [ string ] interface { } ) msg [ " " ] = topic registerSubRequestCodec , err := goavro . NewCodec ( schema . RegisterSubRequest ) if err != nil { return schema . RegisterSubResponseType { } , err } bytes , err := avro . Writer ( msg , registerSubRequestCodec ) if err != nil { return schema . RegisterSubResponseType { } , err } response , err := c . nats . Request ( fmt . Sprintf ( " " , c . target ) , bytes , 2 * time . Second ) if err != nil { if c . nats . LastError ( ) != nil { return schema . RegisterSubResponseType { } , fmt . Errorf ( " " , c . nats . LastError ( ) ) } return schema . RegisterSubResponseType { } , err } avro , _ := avro . NewReader ( response . Data ) j , _ := avro . ByteString ( ) res := schema . RegisterSubResponseType { } err = json . Unmarshal ( j , & res ) if err != nil { return schema . RegisterSubResponseType { } , err } if len ( res . Error ) > 0 { return schema . RegisterSubResponseType { } , fmt . Errorf ( " " , res . Error ) } return res , nil }
RegisterMqttTopic is used to let a client register to a specific MQTT topic.
RegisterMqttTopic is used to let a client register to a specific MQTT topic .