You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Alessio Gottardo <ta...@yahoo.it.INVALID> on 2017/11/06 11:29:59 UTC

Electron/Amqp MessageAnnotations in Golang

Hi there,

I am having a hard time at parsing this field `MessageAnnotations() map[AnnotationKey]interface{}` from this type: https://godoc.org/qpid.apache.org/amqp#Message when receiving a message.

I am connecting to a Azure Event Hub which is supposed to send some useful annotations that I would like to parse e.g.:

- the field called "x-opt-sequence-number" to retrieve the offset of this message in the partition 
- the field called "x-opt-enqueued-time" for the timestamp

Cf. this for more details: https://github.com/Azure/amqpnetlite/blob/master/docs/articles/azure_eventhubs.md

However at runtime when I attempt at accessing that golang field with `amqpMessage.MessageAnnotations()` then I keep getting a panic message saying: `cannot unmarshal AMQP timestamp to *interface {}`

It seems there is a missing switch-case scenario in here: https://github.com/apache/qpid-proton/blob/go1/amqp/unmarshal.go#L248 

Am I doing anything wrong in the way I am trying to access those AMQP fields? 
How could I try to avoid that panic at line 551 in the "default" case of the switch?
I am not familiar with AMQP and golang so I am wondering if I should do things in a different / more idiomatic way instead.

Thank you
Alessio




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: Electron/Amqp MessageAnnotations in Golang

Posted by Alan Conway <ac...@redhat.com>.
On Thu, Nov 9, 2017 at 3:17 PM, Alan Conway <ac...@redhat.com> wrote:

> Apologies for the long delay, this is a bug and was reported previously:
> https://issues.apache.org/jira/browse/PROTON-1429
>
> I am fixing it now, watch the JIRA to be notified when it is fixed. You
> can get the latest code direct from git, the "go get" repo will be updated
> with the next release of proton, which should be fairly soon.
>
> On Mon, Nov 6, 2017 at 6:29 AM, Alessio Gottardo <
> tappoz84@yahoo.it.invalid> wrote:
>
>> Hi there,
>>
>> I am having a hard time at parsing this field `MessageAnnotations()
>> map[AnnotationKey]interface{}` from this type:
>> https://godoc.org/qpid.apache.org/amqp#Message when receiving a message.
>>
>> I am connecting to a Azure Event Hub which is supposed to send some
>> useful annotations that I would like to parse e.g.:
>>
>> - the field called "x-opt-sequence-number" to retrieve the offset of this
>> message in the partition
>> - the field called "x-opt-enqueued-time" for the timestamp
>>
>> Cf. this for more details: https://github.com/Az
>> ure/amqpnetlite/blob/master/docs/articles/azure_eventhubs.md
>>
>> However at runtime when I attempt at accessing that golang field with
>> `amqpMessage.MessageAnnotations()` then I keep getting a panic message
>> saying: `cannot unmarshal AMQP timestamp to *interface {}`
>>
>> It seems there is a missing switch-case scenario in here:
>> https://github.com/apache/qpid-proton/blob/go1/amqp/unmarshal.go#L248
>>
>> Am I doing anything wrong in the way I am trying to access those AMQP
>> fields?
>> How could I try to avoid that panic at line 551 in the "default" case of
>> the switch?
>> I am not familiar with AMQP and golang so I am wondering if I should do
>> things in a different / more idiomatic way instead.
>>
>> Thank you
>> Alessio
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>
>

Re: Electron/Amqp MessageAnnotations in Golang

Posted by Alan Conway <ac...@redhat.com>.
The release is scheduled to happen this week. Meantime:

The apache repo has multiple projects in different languages, so the Go
code is not in the root of the repo as go-get expects. Go get pulls the
"go1" branch, which has only the Go code in the root directory - so when we
release we merge the latest code to that branch. You can do that in your
local repo for yourself:

cd $GOPATH/src/qpid.apache.org
git checkout go1

Then follow merge instructions in readme-go-get.md:

    git pull
    git merge -s recursive -Xsubtree=proton-c/bindings/go/src/
qpid.apache.org master

Alternatively you can set up a GOPATH with multiple entries, one pointing
to the proton-c/bindings/go subdirectory in a complete checkout of the
master branch.


On Thu, Dec 14, 2017 at 11:55 AM, Alessio Gottardo <ta...@yahoo.it>
wrote:

>
>
> On Thursday, 9 November 2017, 20:17:41 GMT, Alan Conway <
> aconway@redhat.com> wrote:
>
>
> > Apologies for the long delay, this is a bug and was reported previously:
> > https://issues.apache.org/jira/browse/PROTON-1429
> >
> > I am fixing it now, watch the JIRA to be notified when it is fixed. You
> can
> > get the latest code direct from git, the "go get" repo will be updated
> with
> > the next release of proton, which should be fairly soon.
>
> Hi there,
>
>
> Is there any news on when this fix will be formally released?
>
>
> Otherwise is there a script to automatically fix the issues regarding the
> git repository path and $GOPATH?
>
> This approach does not make the `electron` code available to the Go
> compiler:
>
>
> ```
> go get qpid.apache.org/electron
> cd $GOPATH/src/qpid.apache.org/
> git checkout 4edafb1a473e3a0d9aa3b9498a3f5bba257aba0a
> ```
>
>
> Having a look here: https://git-wip-us.apache.org/
> repos/asf?p=qpid-proton.git;a=commit;h=4edafb1a473e3a0d9aa3b9498a3f5b
> ba257aba0a
> I can see the path is: `proton-c/bindings/go/src/qpid.apache.org/`
> <http://qpid.apache.org/>
> and I was wondering if there is a script that automatically put that code
> in the expected path inside $GOPATH?
>
>
> Many thanks
> Alessio
>
>
>
>
>

Re: Electron/Amqp MessageAnnotations in Golang

Posted by Alessio Gottardo <ta...@yahoo.it.INVALID>.
 

    On Thursday, 9 November 2017, 20:17:41 GMT, Alan Conway <ac...@redhat.com> wrote:  
 
 > Apologies for the long delay, this is a bug and was reported previously:> https://issues.apache.org/jira/browse/PROTON-1429>> I am fixing it now, watch the JIRA to be notified when it is fixed. You can> get the latest code direct from git, the "go get" repo will be updated with> the next release of proton, which should be fairly soon.
Hi there,

Is there any news on when this fix will be formally released? 

Otherwise is there a script to automatically fix the issues regarding the git repository path and $GOPATH? 
This approach does not make the `electron` code available to the Go compiler: 

```go get qpid.apache.org/electroncd $GOPATH/src/qpid.apache.org/git checkout 4edafb1a473e3a0d9aa3b9498a3f5bba257aba0a```

Having a look here: https://git-wip-us.apache.org/repos/asf?p=qpid-proton.git;a=commit;h=4edafb1a473e3a0d9aa3b9498a3f5bba257aba0a I can see the path is: `proton-c/bindings/go/src/qpid.apache.org/` and I was wondering if there is a script that automatically put that code in the expected path inside $GOPATH?

Many thanks Alessio



  

Re: Electron/Amqp MessageAnnotations in Golang

Posted by Alan Conway <ac...@redhat.com>.
On Fri, Nov 10, 2017 at 8:28 AM, Jiri Danek < jdanek@redhat.com > wrote:

> On Fri, Nov 10, 2017 at 1:10 PM, Alessio Gottardo
> <tappoz84@yahoo.it.invalid
> > wrote:
> >
> > Out of curiosity is there a specific reason for `panic`ing in the
> > `default` case instead of returning an `error`?I just became aware of
> this
> > `recover` mechanism in go to handle a runtime `panic` thrown somewhere
> > else, but that's going to make the code quite a bit more complicated. I
> was
> > wondering if it would have been easier to return an error to whoever uses
> > the `amqp` go wrapper, but I see that could have quite of an impact on
> the
> > codebase as it is at the moment.
> > Thank you for the fix.Alessio
> >
>
> I was thinking the same thing.I read somewhere that `panic`s in Go are
> intended to not cross library boundaries (and not be part of the API).
>  -



Exactly - the panics do not cross library boundaries (unless there's a bug)
and are not part of the API. You'll see that the exported Marshal and
Unmarshal functions recover from the panic and return an error instead.

This is a trick I copied from some of the standard libraries that do
similar marshal/unmarshal (e.g. xml and json) - exception-like
panic/recover inside the package, but return error at the boundaries.
Nowadays I have gotten to appreciate Go's very explicit error return style,
so I don't use that trick much anymore, but in this particular package it
works well so I left it there.

Re: Electron/Amqp MessageAnnotations in Golang

Posted by Jiri Danek <jd...@redhat.com>.
On Fri, Nov 10, 2017 at 1:10 PM, Alessio Gottardo <tappoz84@yahoo.it.invalid
> wrote:
>
> Out of curiosity is there a specific reason for `panic`ing in the
> `default` case instead of returning an `error`?I just became aware of this
> `recover` mechanism in go to handle a runtime `panic` thrown somewhere
> else, but that's going to make the code quite a bit more complicated. I was
> wondering if it would have been easier to return an error to whoever uses
> the `amqp` go wrapper, but I see that could have quite of an impact on the
> codebase as it is at the moment.
> Thank you for the fix.Alessio
>

I was thinking the same thing. I read somewhere that `panic`s in Go are
intended to not cross library boundaries (and not be part of the API).
-- 
Jiri Daněk

Re: Electron/Amqp MessageAnnotations in Golang

Posted by Alessio Gottardo <ta...@yahoo.it.INVALID>.
 Thank you Alan, very much appreciated :)
Out of curiosity is there a specific reason for `panic`ing in the `default` case instead of returning an `error`?I just became aware of this `recover` mechanism in go to handle a runtime `panic` thrown somewhere else, but that's going to make the code quite a bit more complicated. I was wondering if it would have been easier to return an error to whoever uses the `amqp` go wrapper, but I see that could have quite of an impact on the codebase as it is at the moment.
Thank you for the fix.Alessio
    On Thursday, 9 November 2017, 20:17:41 GMT, Alan Conway <ac...@redhat.com> wrote:  
 
 Apologies for the long delay, this is a bug and was reported previously:
https://issues.apache.org/jira/browse/PROTON-1429

I am fixing it now, watch the JIRA to be notified when it is fixed. You can
get the latest code direct from git, the "go get" repo will be updated with
the next release of proton, which should be fairly soon.

On Mon, Nov 6, 2017 at 6:29 AM, Alessio Gottardo <ta...@yahoo.it.invalid>
wrote:

> Hi there,
>
> I am having a hard time at parsing this field `MessageAnnotations()
> map[AnnotationKey]interface{}` from this type:
> https://godoc.org/qpid.apache.org/amqp#Message when receiving a message.
>
> I am connecting to a Azure Event Hub which is supposed to send some useful
> annotations that I would like to parse e.g.:
>
> - the field called "x-opt-sequence-number" to retrieve the offset of this
> message in the partition
> - the field called "x-opt-enqueued-time" for the timestamp
>
> Cf. this for more details: https://github.com/
> Azure/amqpnetlite/blob/master/docs/articles/azure_eventhubs.md
>
> However at runtime when I attempt at accessing that golang field with
> `amqpMessage.MessageAnnotations()` then I keep getting a panic message
> saying: `cannot unmarshal AMQP timestamp to *interface {}`
>
> It seems there is a missing switch-case scenario in here:
> https://github.com/apache/qpid-proton/blob/go1/amqp/unmarshal.go#L248
>
> Am I doing anything wrong in the way I am trying to access those AMQP
> fields?
> How could I try to avoid that panic at line 551 in the "default" case of
> the switch?
> I am not familiar with AMQP and golang so I am wondering if I should do
> things in a different / more idiomatic way instead.
>
> Thank you
> Alessio
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>
  

Re: Electron/Amqp MessageAnnotations in Golang

Posted by Alan Conway <ac...@redhat.com>.
Apologies for the long delay, this is a bug and was reported previously:
https://issues.apache.org/jira/browse/PROTON-1429

I am fixing it now, watch the JIRA to be notified when it is fixed. You can
get the latest code direct from git, the "go get" repo will be updated with
the next release of proton, which should be fairly soon.

On Mon, Nov 6, 2017 at 6:29 AM, Alessio Gottardo <ta...@yahoo.it.invalid>
wrote:

> Hi there,
>
> I am having a hard time at parsing this field `MessageAnnotations()
> map[AnnotationKey]interface{}` from this type:
> https://godoc.org/qpid.apache.org/amqp#Message when receiving a message.
>
> I am connecting to a Azure Event Hub which is supposed to send some useful
> annotations that I would like to parse e.g.:
>
> - the field called "x-opt-sequence-number" to retrieve the offset of this
> message in the partition
> - the field called "x-opt-enqueued-time" for the timestamp
>
> Cf. this for more details: https://github.com/
> Azure/amqpnetlite/blob/master/docs/articles/azure_eventhubs.md
>
> However at runtime when I attempt at accessing that golang field with
> `amqpMessage.MessageAnnotations()` then I keep getting a panic message
> saying: `cannot unmarshal AMQP timestamp to *interface {}`
>
> It seems there is a missing switch-case scenario in here:
> https://github.com/apache/qpid-proton/blob/go1/amqp/unmarshal.go#L248
>
> Am I doing anything wrong in the way I am trying to access those AMQP
> fields?
> How could I try to avoid that panic at line 551 in the "default" case of
> the switch?
> I am not familiar with AMQP and golang so I am wondering if I should do
> things in a different / more idiomatic way instead.
>
> Thank you
> Alessio
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>