Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from rsocket/cloudevents
Cloudevents
- Loading branch information
Showing
16 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.4.10' | ||
__version__ = '0.4.11' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Any | ||
|
||
from cloudevents.conversion import to_json, from_json | ||
from cloudevents.pydantic import CloudEvent | ||
|
||
from rsocket.payload import Payload | ||
|
||
|
||
def cloud_event_deserialize(cls, payload: Payload) -> Any: | ||
if cls == CloudEvent: | ||
return from_json(CloudEvent, payload.data) | ||
|
||
return payload | ||
|
||
|
||
def cloud_event_serialize(cls, value: Any) -> Payload: | ||
if cls == CloudEvent: | ||
return Payload(to_json(value)) | ||
|
||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
|
||
from cloudevents.conversion import to_json, from_json | ||
from cloudevents.pydantic import CloudEvent | ||
|
||
from rsocket.cloudevents.serialize import cloud_event_deserialize, cloud_event_serialize | ||
from rsocket.extensions.helpers import composite, route | ||
from rsocket.extensions.mimetypes import WellKnownMimeTypes | ||
from rsocket.payload import Payload | ||
from rsocket.routing.request_router import RequestRouter | ||
from rsocket.routing.routing_request_handler import RoutingRequestHandler | ||
|
||
|
||
async def test_routed_cloudevents(lazy_pipe): | ||
router = RequestRouter(cloud_event_deserialize, | ||
cloud_event_serialize) | ||
|
||
def handler_factory(): | ||
return RoutingRequestHandler(router) | ||
|
||
@router.response('cloud_event') | ||
async def response_request(value: CloudEvent) -> CloudEvent: | ||
return CloudEvent.create(attributes={ | ||
'type': 'io.spring.event.Foo', | ||
'source': 'https://spring.io/foos' | ||
}, data=json.dumps(json.loads(value.data))) | ||
|
||
async with lazy_pipe( | ||
client_arguments={'metadata_encoding': WellKnownMimeTypes.MESSAGE_RSOCKET_COMPOSITE_METADATA}, | ||
server_arguments={'handler_factory': handler_factory}) as (server, client): | ||
event = CloudEvent.create(attributes={ | ||
'type': 'io.spring.event.Foo', | ||
'source': 'https://spring.io/foos' | ||
}, data=json.dumps({'value': 'Dave'})) | ||
|
||
response = await client.request_response(Payload(data=to_json(event), metadata=composite(route('cloud_event')))) | ||
|
||
response_event = from_json(CloudEvent, response.data) | ||
response_data = json.loads(response_event.data) | ||
|
||
assert response_data['value'] == 'Dave' |