You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-2Lines changed: 63 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,16 @@ Python User Language Support for [Spawn](https://github.com/eigr/spawn).
6
6
1.[Overview](#overview)
7
7
2.[Getting Started](#getting-started)
8
8
3.[Advanced Use Cases](#advanced-use-cases)
9
+
-[Types of Actors](#types-of-actors)
9
10
-[Side Effects](#side-effects)
10
11
-[Broadcast](#broadcast)
11
12
-[Forward](#forward)
12
13
-[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)
14
19
-[Packing with Containers](#packing-with-containers)
15
20
-[Defining an ActorSytem](#defining-an-actorsytem)
16
21
-[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
137
142
## Advanced Use Cases
138
143
TODO
139
144
145
+
### Types of Actors
146
+
TODO
147
+
140
148
### Side Effects
141
149
TODO
142
150
143
151
### 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.
145
164
146
165
```python
147
166
from domain.domain_pb2 import JoeState, Request, Reply
@@ -190,6 +209,48 @@ TODO
190
209
### Pipe
191
210
TODO
192
211
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))
0 commit comments