go-sdk/examples/service
mikeee e45054d1f6
introduces go1.22 to tests (and misc cleanup) (#504)
* introduces go1.22

- dapr-bot updated to use go1.22
- adds go1.22 to the test jobs
- adds go1.22 to tooling tests

Signed-off-by: mikeee <hey@mike.ee>

* remove 1.20 tests

Signed-off-by: mikeee <hey@mike.ee>

* dapr-bot workflow changes

- retrieve go version from go.mod
- run go mod tidy rather than go get

Signed-off-by: mikeee <hey@mike.ee>

* bump action versions and release go version is now from go.mod

Signed-off-by: mikeee <hey@mike.ee>

* bump main and tool mod files to 1.21

Signed-off-by: mikeee <hey@mike.ee>

* fix dapr-bot test

Signed-off-by: mikeee <hey@mike.ee>

* test dapr-bot using go version from go.mod

Signed-off-by: mikeee <hey@mike.ee>

* bump action versions and remove explicit caching

Signed-off-by: mikeee <hey@mike.ee>

* bump examples to go1.21 and bump deps

Signed-off-by: mikeee <hey@mike.ee>

* bump compatibility check to 1.21 in the make flow

Signed-off-by: mikeee <hey@mike.ee>

* bump to dapr1.13rc2

Signed-off-by: mikeee <hey@mike.ee>

* tidy sums

Signed-off-by: mikeee <hey@mike.ee>

* empty commit to trigger tests (flaky example service validation)

Signed-off-by: mikeee <hey@mike.ee>

* remove conditionals for modtidy/checkdiff runs

Signed-off-by: mikeee <hey@mike.ee>

---------

Signed-off-by: mikeee <hey@mike.ee>
2024-02-08 10:08:28 -08:00
..
client allow passage of metadata to state store API (#262) 2022-02-24 09:39:05 +08:00
config minor reorg of 'examples' folder (#178) 2021-06-24 09:51:01 -07:00
custom-grpc-client allow passage of metadata to state store API (#262) 2022-02-24 09:39:05 +08:00
serving replace license headers (#232) 2021-12-14 12:06:12 -08:00
Makefile Add documentation and example to deal with gRPC 4mb limit (#197) 2021-08-31 07:19:27 -07:00
README.md Update protos and client's configuration methods with stable config api (#391) 2023-05-17 22:40:52 -07:00
go.mod introduces go1.22 to tests (and misc cleanup) (#504) 2024-02-08 10:08:28 -08:00
go.sum introduces go1.22 to tests (and misc cleanup) (#504) 2024-02-08 10:08:28 -08:00

README.md

Dapr Go client example

The examples/service folder contains a Dapr enabled serving app and a client app that uses this SDK to invoke Dapr API for state and events, The serving app is available as HTTP or gRPC. The client app can target either one of these for service to service and binding invocations.

To run this example, start by first launching the service in either HTTP or gRPC:

Prepare

  • Dapr installed

HTTP

dapr run --app-id serving \
         --app-protocol http \
         --app-port 8080 \
         --dapr-http-port 3500 \
         --log-level debug \
         --resources-path ./config \
         go run ./serving/http/main.go

gRPC

dapr run --app-id serving \
         --app-protocol grpc \
         --app-port 50001 \
         --dapr-grpc-port 3500 \
         --log-level debug \
         --resources-path ./config \
         go run ./serving/grpc/main.go

Client

Once one of the above services is running, launch the client:

dapr run --app-id caller \
         --resources-path ./config \
         --log-level debug \
         go run ./client/main.go

Custom gRPC client

Launch the DAPR client with custom gRPC client to accept and receive payload size > 4 MB:

dapr run --app-id custom-grpc-client \
		 -d ./config \
		 --dapr-http-max-request-size 41 \
		 --log-level debug \
		 go run ./custom-grpc-client/main.go

API

PubSub

Publish JSON content

curl -d '{ "from": "John", "to": "Lary", "message": "hi" }' \
     -H "Content-type: application/json" \
     "http://localhost:3500/v1.0/publish/messages/topic1"

Publish XML content (read as text)

curl -d '<message><from>John</from><to>Lary</to></message>' \
     -H "Content-type: application/xml" \
     "http://localhost:3500/v1.0/publish/messages/topic1"

Publish BIN content

curl -d '0x18, 0x2d, 0x44, 0x54, 0xfb, 0x21, 0x09, 0x40' \
     -H "Content-type: application/octet-stream" \
     "http://localhost:3500/v1.0/publish/messages/topic1"

Service Invocation

Invoke service with JSON payload

curl -d '{ "from": "John", "to": "Lary", "message": "hi" }' \
     -H "Content-type: application/json" \
     "http://localhost:3500/v1.0/invoke/serving/method/echo"

Invoke service with plain text message

curl -d "ping" \
     -H "Content-type: text/plain;charset=UTF-8" \
     "http://localhost:3500/v1.0/invoke/serving/method/echo"

Invoke service with no content

curl -X DELETE \
    "http://localhost:3500/v1.0/invoke/serving/method/echo?k1=v1&k2=v2"

Input Binding

Uses the config/cron.yaml component

Cleanup

dapr stop --app-id serving
(lsof -i:8080 | grep main) | awk '{print $2}' | xargs  kill