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
+1-100Lines changed: 1 addition & 100 deletions
Original file line number
Diff line number
Diff line change
@@ -951,103 +951,4 @@ consumer.destroy()
951
951
952
952
```python
953
953
memphis.is_connected()
954
-
```
955
-
956
-
### Creating a Memphis function
957
-
Memphis provides a create_function utility for more easily creatin Memphis Functions.
958
-
959
-
The user created `event_handler` will be called for every message in the given batch of events. The user's `event_handler` will take in a `msg_payload` as bytes, `msg_headers` as a dict and `inputs` as a dict, and should return a modified version of the payload and headers in the same data types.
960
-
961
-
The user function should raise an exception if the message processing has failed. If any exception is raised (deliberately or by a failed operation) the message will be sent to the dead letter station.
962
-
963
-
If the returned modified version of the `msg_payload` or `msg_headers` are returned as `None`, then the message will be skipped and will not be sent to the station or dead letter station.
964
-
965
-
> Make sure to encode the modified `msg_payload` bytes object with utf-8 encoding!
966
-
967
-
This example function takes the bytes object `msg_payload` and encodes it into a string so that it may be parsed as JSON.
968
-
969
-
```python
970
-
import json
971
-
import base64
972
-
from memphis.functions import create_function
973
-
974
-
defhandler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format <file name>.<function name>
If the user would want to have a message that they would want to validate and send to the dead letter station if the validation fails then the user can raise an exception. In the following example, the field `check` is simply a boolean. The following function will send any messages which fail the `check` to the dead letter station.
986
-
987
-
```python
988
-
import json
989
-
import base64
990
-
from memphis.functions import create_function
991
-
992
-
defhandler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format <file name>.<function name>
If a user would rather just skip the message and not have it be sent to the station or dead letter station, the cuser could instead return `None`, `None`:
1005
-
1006
-
```python
1007
-
import json
1008
-
import base64
1009
-
from memphis.functions import create_function
1010
-
1011
-
defhandler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format <file name>.<function name>
Lastly, if the user is using another data format like Protocol Buffers, the user may simply decode the `msg_payload` into that format instead of JSON. Assuming we have a .proto definition like this:
1024
-
```proto
1025
-
syntax = "proto3";
1026
-
package protobuf_example;
1027
-
1028
-
message Message{
1029
-
string data_field = 1;
1030
-
}
1031
-
```
1032
-
1033
-
We can decode this and get the data_field out like this:
1034
-
1035
-
```python
1036
-
import json
1037
-
import base64
1038
-
from memphis.functions import create_function
1039
-
import message_pb2
1040
-
1041
-
defhandler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format <file name>.<function name>
0 commit comments