Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe to C2D events throws error while receiving the events on device side #80

Open
PremSahooESL opened this issue May 29, 2023 · 17 comments

Comments

@PremSahooESL
Copy link

PremSahooESL commented May 29, 2023

Go Version: go 1.19

ERROR message parse error: invalid semicolon separator in query

      c, err := iotdevice.NewFromConnectionString(
		iotmqtt.New(), "xxxxxxxxxxxxxxxxxxxx",
	)
	if err != nil {
		log.Fatal(err)
	}

	// connect to the iothub
	if err = c.Connect(context.Background()); err != nil {
		log.Fatal(err)
	}

	// receive a cloud-to-device message
	eventSub, err := c.SubscribeEvents(context.Background())

	for msg := range eventSub.C() {
		fmt.Println(msg.Payload)
	}

	if err := eventSub.Err(); err != nil {
		log.Fatal(err)
	}
@amenzhinsky
Copy link
Owner

Something must be wrong with the connection url

@PremSahooESL
Copy link
Author

PremSahooESL commented May 29, 2023

Connection has been established. It also gets triggered upon events arrival. But with the below error

ERROR message parse error: invalid semicolon separator in query

Below is the sample connection URL I used:

HostName=xxxxxxx.azure-devices.net;SharedAccessKeyName=device;DeviceId=MY_GO_TEST;SharedAccessKey=xxxxxxxxx

@vishal210893
Copy link

Hi, @amenzhinsky is there any update?

@PremSahooESL
Copy link
Author

PremSahooESL commented Jun 6, 2023

@amenzhinsky Do you have any concerns on above connection string format? If so then how come the client could get authorized with above connection string format. But could not parse the data and throws parse error.

Is this SDK able to receive data in your case?

@amenzhinsky
Copy link
Owner

@PremSahooESL it seems parseCloudToDeviceTopic fails to parse the topic name of the incoming message, could you log it in your app to investigate what causes the problem?

@PremSahooESL
Copy link
Author

Thanks for the response. Sure let me check..

@PremSahooESL
Copy link
Author

PremSahooESL commented Jun 7, 2023

Below is the Topic Name What I received from: This could not be parsed by parseQuery() function on url.go

$.to=/devices/PREM_GO_TEST/messages/deviceBound&$.ct=text/plain; charset=UTF-8&$.ce=

@PremSahooESL
Copy link
Author

Is it something different or unexpected which comes from C2D by IotHub?

@amenzhinsky
Copy link
Owner

That's odd, there's a preparation of this type of queries for the following parsing.

https://github.com/amenzhinsky/iothub/blob/master/iotdevice/transport/mqtt/mqtt.go#L280

Could you make sure that parseCloudToDeviceTopic throws the error?

@PremSahooESL
Copy link
Author

PremSahooESL commented Jun 7, 2023

Below code throws the error:
parseCloudToDeviceTopic() -> ParseQuery() -> parseQuery()

func parseCloudToDeviceTopic(s string) (map[string]string, error) {
	s, err := url.QueryUnescape(s)
	if err != nil {
		return nil, err
	}

	// attributes prefixed with $.,
	// e.g. `messageId` becomes `$.mid`, `to` becomes `$.to`, etc.
	i := strings.Index(s, "$.")
	if i == -1 {
		return nil, errors.New("malformed cloud-to-device topic name")
	}
	q, err := url.ParseQuery(s[i:])
	if err != nil {
		return nil, err
	}

	p := make(map[string]string, len(q))
	for k, v := range q {
		if len(v) != 1 {
			return nil, fmt.Errorf("unexpected number of property values: %d", len(q))
		}
		p[k] = v[0]
	}
	return p, nil
}

@PremSahooESL
Copy link
Author

I could see below line is missing from above code:

https://github.com/amenzhinsky/iothub/blob/master/iotdevice/transport/mqtt/mqtt.go#L280

@amenzhinsky
Copy link
Owner

7eb906f

Could you update to the latest version?

@PremSahooESL
Copy link
Author

it works now. Thanks.

@PremSahooESL
Copy link
Author

I will keep posting here if I face other issues. Infact this is the only Github repo for Go Lang SDK for Azure IoT Hub. Hope it supports all basic C2D functions.

@PremSahooESL
Copy link
Author

PremSahooESL commented Jul 24, 2023

i am just trying to send a C-2-D message.

I am trying to use below imports statement. But my application could not start up. It keeps throwing beolow error.

"github.com/amenzhinsky/iothub/iotservice"

image

@PremSahooESL
Copy link
Author

PremSahooESL commented Jul 24, 2023

Looks.... latest Eventhub client.go in this repo is not using latest amqp 1.0.1 lib

image

@PremSahooESL
Copy link
Author

Below is the send() of latest amqp 1.0.1 lib code....

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants