Skip to content

Commit 39997b6

Browse files
gwallace-algorithmiaGordon Wallace
andauthored
Updated sample code for external event processing (#603)
Co-authored-by: Gordon Wallace <gwallace@algorithmia.com>
1 parent 8de6b4b commit 39997b6

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

_pages/event-flows/amazon-sqs.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,13 @@ In the body of your algorithm, paste the code below, replacing `COLLECTION_OWNER
306306

307307
```python
308308
import Algorithmia
309-
310-
client = Algorithmia.client()
309+
from Algorithmia import ADK
311310
312311
def apply(input):
313-
data_uri = "data://COLLECTION_OWNER/COLLECTION_NAME/" + input.get("filename")
314-
client.file(data_uri).put(input.get("data"))
312+
Algorithmia.client().file("data://COLLECTION_OWNER/COLLECTION_NAME/" + input.get("filename")).put(input.get("data"))
313+
314+
algorithm = ADK(apply)
315+
algorithm.init("Algorithmia")
315316
```
316317

317318
<img src="{{site.cdnurl}}{{site.baseurl}}/images/post_images/eventlisteners/algorithmia-web-ide-example-code.png" alt="create algorithm Web IDE">

_pages/event-flows/azure-sb.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,13 @@ In the body of your algorithm, paste the source code below, replacing the `COLLE
233233

234234
```python
235235
import Algorithmia
236-
237-
client = Algorithmia.client()
236+
from Algorithmia import ADK
238237

239238
def apply(input):
240-
data_uri = "data://COLLECTION_OWNER/COLLECTION_NAME/" + input.get("filename")
241-
client.file(data_uri).put(input.get("data"))
239+
Algorithmia.client().file("data://COLLECTION_OWNER/COLLECTION_NAME/" + input.get("filename")).put(input.get("data"))
240+
241+
algorithm = ADK(apply)
242+
algorithm.init("Algorithmia")
242243
```
243244

244245
<img src="{{site.cdnurl}}{{site.baseurl}}/images/post_images/eventlisteners/algorithmia-web-ide-azure-sb-subscriber.png">
@@ -326,20 +327,20 @@ In the body of your algorithm, paste the source code below, replacing the `QUEUE
326327

327328
```python
328329
import os
330+
import json
329331

330332
import Algorithmia
333+
from Algorithmia import ADK
331334
from azure.servicebus import ServiceBusClient, ServiceBusMessage
332335

333-
CONNECTION_STR = os.getenv("CONNECTION_STR")
336+
CONNECTION_STR = "CONNECTION_STR"
334337
QUEUE_NAME = "QUEUE_NAME"
335338

336-
337339
def send_single_message(sender, message):
338340
# Send the message to the queue
339341
sender.send_messages(message)
340342
print("Sent a single message.")
341343

342-
343344
def apply(input):
344345
"""Send a message to the queue.
345346
@@ -348,7 +349,7 @@ def apply(input):
348349
"""
349350

350351
# Create a Service Bus message
351-
message = ServiceBusMessage(input.get("data"))
352+
message = ServiceBusMessage(json.dumps(input))
352353
# Create a Service Bus client using the connection string
353354
servicebus_client = ServiceBusClient.from_connection_string(
354355
conn_str=CONNECTION_STR,
@@ -360,6 +361,9 @@ def apply(input):
360361
# Send one message
361362
send_single_message(sender, message)
362363
return "Sent a message to the queue."
364+
365+
algorithm = ADK(apply)
366+
algorithm.init("Algorithmia")
363367
```
364368

365369
Click the **Save** and **Build** buttons, and then **Publish** the algorithm.

0 commit comments

Comments
 (0)