go-sdk/examples/service
Mike Nguyen 81312e9da9
merge release-1.12 into main (#703)
* Adding the name of the failing activity. For more detail (#678)

Signed-off-by: arturo <jarturotrenard@gmail.com>

* add deadlettertopic support to non-streaming subscriptions (#685)

* add deadlettertopic support to non-streaming subscriptions

Signed-off-by: yaron2 <schneider.yaron@live.com>

* fix tests

Signed-off-by: yaron2 <schneider.yaron@live.com>

---------

Signed-off-by: yaron2 <schneider.yaron@live.com>

* Pick #674 and bump to rc13 (#686)

* Bump gover, tag, x/deps and dapr (#674)

* release: bump to rc2

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

* chore: upgrade x/net and x/crypto

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

* release: bump go to 1.23.5 and dapr to rc5

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

* ci: bump validation workflow versions

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

* bump cli and runtime to latest rc

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

* chore: bump dapr to rc7 and dt-go to head

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

* chore: bump to rc8

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

* chore(release): bump to latest

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

---------

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

* chore: bump cli and runtime vers

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

* chore: bump to rc13

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

---------

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

* feat: reconnect stream when grpc code is unknown / unavailable (#692)

* feat: reconnect stream when grpc code is unknown / unavailable

Signed-off-by: Eileen Yu <eileenylj@gmail.com>

* log error for closing stream

Signed-off-by: Eileen Yu <eileenylj@gmail.com>

---------

Signed-off-by: Eileen Yu <eileenylj@gmail.com>

* ci: include pre-release label for RCs (#675)

* ci: include pre-release label for RCs

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

* ci: enumerate if statements

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

---------

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

* docs(sdk): add basic workflow example (#691)

* docs(sdk): add basic workflow example

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

* docs: fix indentations

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

---------

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

* update conversation api field name (#695)

Signed-off-by: yaron2 <schneider.yaron@live.com>

* fix(examples): update deprecated flag (#689)

* fix(examples): update deprecated flag

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

* ci: test cli PR

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

* test(service): bump body size to 41Mi

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

* chore: bump cli to rc6 and runtime to rc16

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

---------

Signed-off-by: Mike Nguyen <hey@mike.ee>
Co-authored-by: Yaron Schneider <schneider.yaron@live.com>

* release: v1.12.0 version (#700)

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

* ci: revert rc tests (#701)

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

---------

Signed-off-by: arturo <jarturotrenard@gmail.com>
Signed-off-by: yaron2 <schneider.yaron@live.com>
Signed-off-by: mikeee <hey@mike.ee>
Signed-off-by: Mike Nguyen <hey@mike.ee>
Signed-off-by: Eileen Yu <eileenylj@gmail.com>
Co-authored-by: Arturo Trenard <jarturotrenard@gmail.com>
Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
Co-authored-by: Eileen Yu <48944635+Eileen-Yu@users.noreply.github.com>
2025-02-28 12:30:46 -08:00
..
client chore: bump validation dapr runtime to 1.15.0-rc.2 (#667) 2025-01-13 08:37:02 -08:00
config chore: bump validation dapr runtime to 1.15.0-rc.2 (#667) 2025-01-13 08:37:02 -08: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 merge release-1.12 into main (#703) 2025-02-28 12:30:46 -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 \
		 --max-body-size 41Mi \
		 --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