[ 
https://issues.apache.org/jira/browse/PROTON-1415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15881470#comment-15881470
 ] 

Alan Conway commented on PROTON-1415:
-------------------------------------

Thanks for the excellent feedback, all fixed now. Your example is working with 
two small changes.

1. DurableSubscription now takes the link name (aka subscription name), no need 
for separate LinkName() option. Durable subs are perhaps the only reason an 
application would care about link names, and "subscription name" will be more 
familiar to most users than "link name". LinkName() is still available for 
other obscure uses but not needed in this case.

2. The original receive.go example has the PID in the container-id as a crude 
form of uniqueness. For a durable subscription that's wrong, you need a stable 
container-id each time you run the client (e.g. your python example uses 
__file__ as container ID) I dropped that PID in more recent versions of the 
receive example because


Here are the changes:

{code}
modified   go-electron/receive.go
@@ -45,7 +45,8 @@ func main() {
        var wait sync.WaitGroup // Used by main() to wait for all goroutines to 
end.
        wait.Add(len(urls))     // Wait for one goroutine per URL.
 
-       container := electron.NewContainer(fmt.Sprintf("receive[%v]", 
os.Getpid()))
+       // NOTE: for durable subscriptions we must have a consistent 
container-id each time.
+       container := electron.NewContainer("receive")
        connections := make(chan electron.Connection, len(urls)) // Connections 
to close on exit
 
        // Start a goroutine to for each URL to receive messages and send them 
to the messages channel.
@@ -61,7 +62,9 @@ func main() {
                        connections <- c // Save connection so we can Close() 
when main() ends
                        debugf("Message source %s\n", *messageSource)
                        debugf("Subscription name %s\n", *subName)
-                       r, err := c.Receiver(electron.LinkName(*subName), 
electron.Source(*messageSource), electron.DurableSubscription())
+                       // NOTE: The DurableSubscription option sets the link 
name, aka subscription name.
+                       // It does not need to be set separately with LinkName()
+                       r, err := c.Receiver(electron.Source(*messageSource), 
electron.DurableSubscription(*subName))
                        fatalIf(err)
                        // Loop receiving messages and sending them to the 
main() goroutine
                        for {

{code}


> go binding does not create durable subscriber
> ---------------------------------------------
>
>                 Key: PROTON-1415
>                 URL: https://issues.apache.org/jira/browse/PROTON-1415
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: go-binding
>    Affects Versions: 0.17.0
>         Environment: Docker for Windows 1.13.1
> Docker golang:1.7
> ActiveMQ 5.14.3 (Java 1.8.0_111)
>            Reporter: Jeremy Gooch
>            Assignee: Alan Conway
>
> When creating a subscription from Qpid Electron, the subscription name is not 
> set, meaning that durable subscriptions cannot be created.
> Example code -> 
> https://github.com/goochjs/amqp-activemq-python-go/blob/master/go-electron/receive.go
> Go example snippet (setting container ID):-
>       container = electron.NewContainer(fmt.Sprintf("receive-client[%v]", 
> os.Getpid()))
> Go example snippet (failing to set subscription name):-
>       if r, err := c.Receiver(electron.LinkName(SubscriptionName), 
> electron.Source("topic://"+AmqpResourceName)); err == nil {
> For comparison, I have a working Qpid Proton Python client, which sets both 
> connection ID and subscription name -> 
> https://github.com/goochjs/amqp-activemq-python-go/blob/master/python-proton/message_receiver.py
> Python example snippet (setting container ID):-
>       # Name the subscription after the script file name
>         event.container.container_id = __file__
> Python example snippet (setting subscription name):-
>         messaging_connection = event.container.connect(self.url)
>         event.container.create_receiver(
>             messaging_connection,
>             self.resource,
>             name=self.subscription_name,
>             options=durable
>         )



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to