Skip to content

Commit 9bc7d82

Browse files
JoshVanLmikeee
andauthored
Update streaming subscription to understand new initial response (#601)
* Update streaming subscription to understand new initial response Signed-off-by: joshvanl <[email protected]> * Update dapr CLI to 1.14.0-rc.6 Signed-off-by: joshvanl <[email protected]> * Update streamsub name in validate examples Signed-off-by: joshvanl <[email protected]> * Apply suggestions from code review Co-authored-by: Mike Nguyen <[email protected]> Signed-off-by: Josh van Leeuwen <[email protected]> --------- Signed-off-by: joshvanl <[email protected]> Signed-off-by: Josh van Leeuwen <[email protected]> Co-authored-by: Mike Nguyen <[email protected]>
1 parent 7c03c7c commit 9bc7d82

File tree

10 files changed

+37
-23
lines changed

10 files changed

+37
-23
lines changed

.github/workflows/validate_examples.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ jobs:
3232
GOARCH: amd64
3333
GOPROXY: https://proxy.golang.org
3434
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install/install.sh
35-
DAPR_CLI_REF: 19b9de05611ade540b06d2c061f32f6c37093a17
35+
DAPR_CLI_REF: ${{ github.event.inputs.daprcli_commit }}
3636
DAPR_REF: ${{ github.event.inputs.daprdapr_commit }}
3737
CHECKOUT_REPO: ${{ github.repository }}
3838
CHECKOUT_REF: ${{ github.ref }}
3939
outputs:
4040
DAPR_INSTALL_URL: ${{ env.DAPR_INSTALL_URL }}
41-
DAPR_CLI_VER: ${{ steps.outputs.outputs.DAPR_CLI_VER }}
41+
DAPR_CLI_VER: 1.14.0-rc.6
4242
DAPR_CLI_REF: ${{ steps.outputs.outputs.DAPR_CLI_REF }}
43-
DAPR_RUNTIME_VER: 1.14.0-rc.2
43+
DAPR_RUNTIME_VER: 1.14.0-rc.4
4444
CHECKOUT_REPO: ${{ steps.outputs.outputs.CHECKOUT_REPO }}
4545
CHECKOUT_REF: ${{ steps.outputs.outputs.CHECKOUT_REF }}
4646
DAPR_REF: ${{ steps.outputs.outputs.DAPR_REF }}
@@ -150,7 +150,7 @@ jobs:
150150
GOPROXY: https://proxy.golang.org
151151
DAPR_INSTALL_URL: ${{ needs.setup.outputs.DAPR_INSTALL_URL }}
152152
DAPR_CLI_VER: ${{ needs.setup.outputs.DAPR_CLI_VER }}
153-
DAPR_RUNTIME_VER: 1.14.0-rc.2
153+
DAPR_RUNTIME_VER: ${{ needs.setup.outputs.DAPR_RUNTIME_VER }}
154154
DAPR_CLI_REF: ${{ needs.setup.outputs.DAPR_CLI_REF }}
155155
DAPR_REF: ${{ needs.setup.outputs.DAPR_REF }}
156156
CHECKOUT_REPO: ${{ needs.setup.outputs.CHECKOUT_REPO }}
@@ -169,7 +169,7 @@ jobs:
169169
"grpc-service",
170170
"hello-world",
171171
"pubsub",
172-
"bidipubsub",
172+
"streamsub",
173173
"service",
174174
"socket",
175175
"workflow",

client/subscribe.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ func (c *GRPCClient) Subscribe(ctx context.Context, opts SubscriptionOptions) (*
5454
return nil, err
5555
}
5656

57-
return &Subscription{
57+
s := &Subscription{
5858
stream: stream,
59-
}, nil
59+
}
60+
61+
return s, nil
6062
}
6163

6264
func (c *GRPCClient) SubscribeWithHandler(ctx context.Context, opts SubscriptionOptions, handler SubscriptionHandleFunction) (func() error, error) {
@@ -99,10 +101,11 @@ func (s *Subscription) Close() error {
99101
}
100102

101103
func (s *Subscription) Receive() (*SubscriptionMessage, error) {
102-
event, err := s.stream.Recv()
104+
resp, err := s.stream.Recv()
103105
if err != nil {
104106
return nil, err
105107
}
108+
event := resp.GetEventMessage()
106109

107110
data := any(event.GetData())
108111
if len(event.GetData()) > 0 {
@@ -181,8 +184,8 @@ func (s *SubscriptionMessage) respond(status pb.TopicEventResponse_TopicEventRes
181184
defer s.sub.lock.Unlock()
182185

183186
return s.sub.stream.Send(&pb.SubscribeTopicEventsRequestAlpha1{
184-
SubscribeTopicEventsRequestType: &pb.SubscribeTopicEventsRequestAlpha1_EventResponse{
185-
EventResponse: &pb.SubscribeTopicEventsResponseAlpha1{
187+
SubscribeTopicEventsRequestType: &pb.SubscribeTopicEventsRequestAlpha1_EventProcessed{
188+
EventProcessed: &pb.SubscribeTopicEventsRequestProcessedAlpha1{
186189
Id: s.ID,
187190
Status: &pb.TopicEventResponse{Status: status},
188191
},
@@ -206,7 +209,7 @@ func (c *GRPCClient) subscribeInitialRequest(ctx context.Context, opts Subscript
206209

207210
err = stream.Send(&pb.SubscribeTopicEventsRequestAlpha1{
208211
SubscribeTopicEventsRequestType: &pb.SubscribeTopicEventsRequestAlpha1_InitialRequest{
209-
InitialRequest: &pb.SubscribeTopicEventsInitialRequestAlpha1{
212+
InitialRequest: &pb.SubscribeTopicEventsRequestInitialAlpha1{
210213
PubsubName: opts.PubsubName, Topic: opts.Topic,
211214
Metadata: opts.Metadata, DeadLetterTopic: opts.DeadLetterTopic,
212215
},
@@ -216,5 +219,16 @@ func (c *GRPCClient) subscribeInitialRequest(ctx context.Context, opts Subscript
216219
return nil, errors.Join(err, stream.CloseSend())
217220
}
218221

222+
resp, err := stream.Recv()
223+
if err != nil {
224+
return nil, errors.Join(err, stream.CloseSend())
225+
}
226+
227+
switch resp.GetSubscribeTopicEventsResponseType().(type) {
228+
case *pb.SubscribeTopicEventsResponseAlpha1_InitialResponse:
229+
default:
230+
return nil, fmt.Errorf("unexpected initial response from server : %v", resp)
231+
}
232+
219233
return stream, nil
220234
}

examples/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
1919
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2020
github.com/cespare/xxhash/v2 v2.3.0 // indirect
21-
github.com/dapr/dapr v1.14.0-rc.2 // indirect
21+
github.com/dapr/dapr v1.14.0-rc.5 // indirect
2222
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
2323
github.com/go-chi/chi/v5 v5.1.0 // indirect
2424
github.com/go-logr/logr v1.4.2 // indirect

examples/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyY
77
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
88
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
99
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
10-
github.com/dapr/dapr v1.14.0-rc.2 h1:wuXninZLTyokeztCinVIVAc9mpVYJS8QyxecPCLdlY8=
11-
github.com/dapr/dapr v1.14.0-rc.2/go.mod h1:uZMuD9K7y+LKSsQUoSAvv1Yn8Cim9X/9ZQ9XuTobyP8=
10+
github.com/dapr/dapr v1.14.0-rc.5 h1:oTZPcT5fwda6bCMxrfenem6tOyeqW1nastxTwWInBCY=
11+
github.com/dapr/dapr v1.14.0-rc.5/go.mod h1:IQWNthXF/I+qqlW4I0T+F4hCu74eKon4vjhpNvoBl8A=
1212
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1313
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
1414
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

examples/bidipubsub/README.md renamed to examples/streamsub/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dapr run --app-id sub \
3535
--dapr-http-port 3500 \
3636
--log-level debug \
3737
--resources-path ./config \
38-
go run bidisub/bidisub.go
38+
go run sub/sub.go
3939
```
4040

4141
<!-- END_STEP -->
File renamed without changes.

examples/bidipubsub/bidisub/bidisub.go renamed to examples/streamsub/sub/sub.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,27 @@ func main() {
4545
eventHandler,
4646
)
4747
if err != nil {
48-
log.Fatal(err)
48+
log.Fatalf("failed to subscribe to topic: %v", err)
4949
}
50+
fmt.Printf(">>Created subscription messages/sendorder\n")
5051

5152
// Another method of streaming subscriptions, this time for the topic "neworder".
5253
// The returned `sub` object is used to receive messages.
5354
// `sub` must be closed once it's no longer needed.
54-
5555
sub, err := client.Subscribe(context.Background(), daprd.SubscriptionOptions{
5656
PubsubName: "messages",
5757
Topic: "neworder",
5858
DeadLetterTopic: &deadLetterTopic,
5959
})
6060
if err != nil {
61-
log.Fatal(err)
61+
log.Fatalf("failed to subscribe to topic: %v", err)
6262
}
63-
fmt.Printf(">>Created subscription\n")
63+
fmt.Printf(">>Created subscription messages/neworder\n")
6464

6565
for i := 0; i < 3; i++ {
6666
msg, err := sub.Receive()
6767
if err != nil {
68-
log.Fatalf("error receiving message: %v", err)
68+
log.Fatalf("Error receiving message: %v", err)
6969
}
7070
log.Printf(">>Received message\n")
7171
log.Printf("event - PubsubName: %s, Topic: %s, ID: %s, Data: %s\n", msg.PubsubName, msg.Topic, msg.ID, msg.RawData)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/dapr/go-sdk
33
go 1.22.5
44

55
require (
6-
github.com/dapr/dapr v1.14.0-rc.2
6+
github.com/dapr/dapr v1.14.0-rc.5
77
github.com/go-chi/chi/v5 v5.1.0
88
github.com/golang/mock v1.6.0
99
github.com/google/uuid v1.6.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
22
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
33
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4-
github.com/dapr/dapr v1.14.0-rc.2 h1:wuXninZLTyokeztCinVIVAc9mpVYJS8QyxecPCLdlY8=
5-
github.com/dapr/dapr v1.14.0-rc.2/go.mod h1:uZMuD9K7y+LKSsQUoSAvv1Yn8Cim9X/9ZQ9XuTobyP8=
4+
github.com/dapr/dapr v1.14.0-rc.5 h1:oTZPcT5fwda6bCMxrfenem6tOyeqW1nastxTwWInBCY=
5+
github.com/dapr/dapr v1.14.0-rc.5/go.mod h1:IQWNthXF/I+qqlW4I0T+F4hCu74eKon4vjhpNvoBl8A=
66
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
77
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
88
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=

0 commit comments

Comments
 (0)