Skip to content

Commit

Permalink
push simple_subscriber subscriber files
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhop993 committed Oct 4, 2021
1 parent e490e67 commit 0731af6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
7 changes: 1 addition & 6 deletions ibm-mq/simple_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/ibm-messaging/mq-golang/v5/ibmmq"
"strings"
)

type SubscriberConfig struct {
Expand Down Expand Up @@ -82,7 +81,6 @@ func (c *SimpleSubscriber) Subscribe(ctx context.Context, handle func(context.Co
for {
msgAvail := true
for msgAvail == true && err == nil {
var datalen int
mqmd := ibmmq.NewMQMD()
// The GET requires control structures, the Message Descriptor (MQMD)
// and Get Options (MQGMO). Create those with default values.
Expand All @@ -95,21 +93,18 @@ func (c *SimpleSubscriber) Subscribe(ctx context.Context, handle func(context.Co
gmo.Options |= ibmmq.MQGMO_WAIT
gmo.WaitInterval = c.WaitInterval // The WaitInterval is in milliseconds
buffer := make([]byte, 0, 1024)
buffer, datalen, err = qObject.GetSlice(mqmd, gmo, buffer)
buffer, _, err = qObject.GetSlice(mqmd, gmo, buffer)

if err != nil {
msgAvail = false
mqReturn := err.(*ibmmq.MQReturn)
if mqReturn.MQRC != ibmmq.MQRC_NO_MSG_AVAILABLE {
fmt.Println("NO_MSG_AVAILABLE")
handle(ctx, nil, nil, err)
} else {
err = nil
}
} else {
msgAvail = true
fmt.Printf("Got message of length %d: ", datalen)
fmt.Println(strings.TrimSpace(string(buffer)))
handle(ctx, buffer, nil, err)
}
}
Expand Down
6 changes: 1 addition & 5 deletions ibm-mq/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (c *Subscriber) Subscribe(ctx context.Context, handle func(context.Context,
for {
msgAvail := true
for msgAvail == true && err == nil {
var datalen int
mqmd := ibmmq.NewMQMD()
// The GET requires control structures, the Message Descriptor (MQMD)
// and Get Options (MQGMO). Create those with default values.
Expand All @@ -87,21 +86,18 @@ func (c *Subscriber) Subscribe(ctx context.Context, handle func(context.Context,
gmo.Options |= ibmmq.MQGMO_WAIT // The WaitInterval is in milliseconds
gmo.WaitInterval = c.WaitInterval
buffer := make([]byte, 0, 1024)
buffer, datalen, err = qObject.GetSlice(mqmd, gmo, buffer)
buffer, _, err = qObject.GetSlice(mqmd, gmo, buffer)

if err != nil {
msgAvail = false
mqReturn := err.(*ibmmq.MQReturn)
if mqReturn.MQRC != ibmmq.MQRC_NO_MSG_AVAILABLE {
fmt.Println("NO_MSG_AVAILABLE")
handle(ctx, nil, err)
} else {
err = nil
}
} else {
msgAvail = true
fmt.Printf("Got message of length %d: ", datalen)
fmt.Println(strings.TrimSpace(string(buffer)))
msg := mq.Message{Data: buffer}
handle(ctx, &msg, err)
}
Expand Down

0 comments on commit 0731af6

Please sign in to comment.