go-sdk/examples/socket
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
..
.gitignore chore: remove the binary and add gitignore (#315) 2022-09-30 20:28:16 -07:00
Makefile Update go version to 1.19 (#403) 2023-05-20 07:36:37 -07:00
README.md fix: fix broken dapr setup links (#468) 2023-10-19 06:36:22 -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
order.go allow passage of metadata to state store API (#262) 2022-02-24 09:39:05 +08:00

README.md

Hello World with Unix domain socket

This tutorial will demonstrate how to instrument your application with Dapr, and run it locally on your machine. You will deploying advanced order applications with Unix domain socket based on Hello World.

There is a great performance imporvement With Unix domain socket, please notice that it does not support on Windows.

Prerequisites

This quickstart requires you to have the following installed on your machine:

Step 1 - Setup Dapr

Step 2 - Understand the code

The order.go is a simple command line application, that implements four commands:

  • put sends an order with configurable order ID.
  • get return the current order number.
  • del deletes the order.
  • seq streams a sequence of orders with incrementing order IDs.

First, the app instantiates Dapr client:

    client, err := dapr.NewClientWithSocket(socket)
    if err != nil {
        panic(err)
    }
    defer client.Close()

Then, depending on the command line argument, the app invokes corresponding method:

Persist the state:

    err := client.SaveState(ctx, stateStoreName, "order", []byte(strconv.Itoa(orderID)), nil)

Retrieve the state:

    item, err := client.GetState(ctx, stateStoreName, "order", nil)

Delete the state:

    err := client.DeleteState(ctx, stateStoreName, "order", nil)

Step 3 - Run the app with Dapr

  1. Build the app
make
  1. Run the app

There are two ways to launch Dapr applications. You can pass the app executable to the Dapr runtime:

dapr run --app-id order-app --log-level error --unix-domain-socket /tmp -- ./order put --id 20
dapr run --app-id order-app --log-level error --unix-domain-socket /tmp ./order get

Alternatively, you can start a standalone Dapr runtime, and call the app from another shell:

dapr run --app-id order-app --log-level error --unix-domain-socket /tmp
./order put --id 10

./order get

To terminate your services, simply stop the "dapr run" process, or use the Dapr CLI "stop" command:

dapr stop --app-id order-app
  1. Run multiple apps

You can run more than one app in Dapr runtime. In this example you will call order seq which sends a sequence of orders. Another instance of the order app will read the state.

dapr run --app-id order-app --log-level error --unix-domain-socket /tmp ./order seq
./order get