Skip to content

Commit 6af7cf1

Browse files
committed
Doc and minor adjusts
1 parent 1e54d52 commit 6af7cf1

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ Python User Language Support for [Spawn](https://github.com/eigr/spawn).
66
1. [Overview](#overview)
77
2. [Getting Started](#getting-started)
88
3. [Advanced Use Cases](#advanced-use-cases)
9+
- [Types of Actors](#types-of-actors)
910
- [Side Effects](#side-effects)
1011
- [Broadcast](#broadcast)
1112
- [Forward](#forward)
1213
- [Pipe](#pipe)
13-
4. [Deploy](#deploy)
14+
4. [Using Actors](#using-actors)
15+
- [Call Named Actors](#call-named-actors)
16+
- [Call Unnamed Actors](#call-unnamed-actors)
17+
- [Async and other options](#async-and-other-options)
18+
5. [Deploy](#deploy)
1419
- [Packing with Containers](#packing-with-containers)
1520
- [Defining an ActorSytem](#defining-an-actorsytem)
1621
- [Defining an ActorHost](#defining-an-actorhost)
@@ -137,11 +142,25 @@ And this is it to start! Now that you know the basics of local development, we c
137142
## Advanced Use Cases
138143
TODO
139144

145+
### Types of Actors
146+
TODO
147+
140148
### Side Effects
141149
TODO
142150

143151
### Broadcast
144-
TODO
152+
153+
Actors in Spawn can subscribe to a thread and receive, as well as broadcast, events for a given thread.
154+
155+
To consume from a topic, you just need to configure the Actor decorator using the channel option as follows:
156+
157+
```python
158+
actor = Actor(settings=ActorSettings(
159+
name="joe", stateful=True, channel="test"))
160+
```
161+
In the case above, the Actor `joe` was configured to receive events that are forwarded to the topic called `test`.
162+
163+
To produce events in a topic, just use the Broadcast Workflow. The example below demonstrates a complete example of producing and consuming events. In this case, the same actor is the event consumer and producer, but in a more realistic scenario, different actors would be involved in these processes.
145164

146165
```python
147166
from domain.domain_pb2 import JoeState, Request, Reply
@@ -190,6 +209,48 @@ TODO
190209
### Pipe
191210
TODO
192211

212+
## Using Actors
213+
214+
### Call Named Actors
215+
216+
```python
217+
# Get abstract actor reference called mike
218+
actor: ActorRef = Spawn.create_actor_ref(
219+
system="spawn-system",
220+
actor_name="joe"
221+
)
222+
223+
request = Request()
224+
request.language = "erlang"
225+
226+
(status, result) = actor.invoke(
227+
action="setLanguage", request=request)
228+
print("Invocation Result Status: " + status)
229+
print("Invocation Result Value: " + str(result.response))
230+
```
231+
232+
### Call Unnamed Actors
233+
234+
```python
235+
# Get abstract actor reference called mike
236+
actor: ActorRef = Spawn.create_actor_ref(
237+
system="spawn-system",
238+
actor_name="mike",
239+
parent="abs_actor"
240+
)
241+
242+
request = Request()
243+
request.language = "erlang"
244+
245+
(status, result) = actor.invoke(
246+
action="setLanguage", request=request)
247+
print("Invocation Result Status: " + status)
248+
print("Invocation Result Value: " + str(result.response))
249+
```
250+
251+
### Async calls and other options
252+
TODO
253+
193254
## Deploy
194255
TODO
195256

example/unnamed_actor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@abstract.action("setLanguage")
1616
def set_language(request: Request, ctx: Context) -> Value:
17+
print("Request -> " + str(request))
1718
print("Current State -> " + str(ctx.state))
1819

1920
reply = Reply()

spawn/eigr/functions/actors/api/reference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, client: SpawnClient, system: str, actor: str, parent: str = N
4646
def invoke(self, action: str, request: any = None, async_mode: bool = False, pooled: bool = False):
4747
req: InvocationRequest = self.__build_request(
4848
action, request, async_mode, pooled)
49+
4950
resp: InvocationResponse = self.__spawn_client.invoke(
5051
self.actor_system, self.actor_name, req)
5152

0 commit comments

Comments
 (0)