How to use the dapr.proto.common_v1.InvokeRequest function in dapr

To help you get started, we’ve selected a few dapr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dapr / python-sdk / tests / clients / test_dapr_grpc_request.py View on Github external
def test_proto_message_data(self):
        # arrange
        fake_req = common_v1.InvokeRequest(method="test")

        # act
        data = InvokeServiceRequestData(data=fake_req)

        # assert
        self.assertIsNotNone(data.data)
        self.assertEqual(
            'type.googleapis.com/dapr.proto.common.v1.InvokeRequest',
            data.data.type_url)
        self.assertIsNotNone(data.data.value)
        self.assertIsNone(data.content_type)
github dapr / python-sdk / tests / clients / test_dapr_grpc_response.py View on Github external
def test_proto(self):
        fake_req = common_v1.InvokeRequest(method="test")
        test_data = GrpcAny()
        test_data.Pack(fake_req)
        resp = InvokeServiceResponse(data=test_data)
        self.assertIsNotNone(resp.data)
github dapr / python-sdk / tests / clients / test_dapr_grpc_response.py View on Github external
def test_unpack(self):
        # arrange
        fake_req = common_v1.InvokeRequest(method="test")
        test_data = GrpcAny()
        test_data.Pack(fake_req)

        # act
        resp = InvokeServiceResponse(data=test_data)
        resp_proto = common_v1.InvokeRequest()
        resp.unpack(resp_proto)

        # assert
        self.assertEqual("test", resp_proto.method)
github dapr / python-sdk / tests / clients / test_dapr_grpc_response.py View on Github external
def test_unpack(self):
        # arrange
        fake_req = common_v1.InvokeRequest(method="test")
        test_data = GrpcAny()
        test_data.Pack(fake_req)

        # act
        resp = InvokeServiceResponse(data=test_data)
        resp_proto = common_v1.InvokeRequest()
        resp.unpack(resp_proto)

        # assert
        self.assertEqual("test", resp_proto.method)
github dapr / python-sdk / examples / invoke-simple / invoke-caller.py View on Github external
from google.protobuf.any_pb2 import Any


# Start a gRPC client
port = os.getenv('DAPR_GRPC_PORT')
channel = grpc.insecure_channel(f"localhost:{port}")
client = api_service_v1.DaprStub(channel)
print(f"Started gRPC client on DAPR_GRPC_PORT: {port}")

# Create a typed message with content type and body
test_message = Any(value='INVOKE_RECEIVED'.encode('utf-8'))

# Invoke the method 'my-method' on receiver 
req = api_v1.InvokeServiceRequest(
    id="invoke-receiver",
    message=common_v1.InvokeRequest(
        method='my-method',
        data=test_message,
        content_type="text/plain; charset=UTF-8")
)
response = client.InvokeService(req)

# Print the response
print(response.content_type)
print(response.data.value)

channel.close()
github dapr / python-sdk / dapr / clients / grpc / client.py View on Github external
metadata (tuple, optional): custom metadata
            http_verb (str, optional): http method verb to call HTTP callee application
            http_querystring (tuple, optional): the tuple to represent query string

        Returns:
            :class:`InvokeServiceResponse` object returned from callee
        """
        req_data = InvokeServiceRequestData(data, content_type)

        http_ext = None
        if http_verb:
            http_ext = self._get_http_extension(http_verb, http_querystring)

        req = api_v1.InvokeServiceRequest(
            id=id,
            message=common_v1.InvokeRequest(
                method=method,
                data=req_data.data,
                content_type=req_data.content_type,
                http_extension=http_ext)
        )

        response, call = self._stub.InvokeService.with_call(req, metadata=metadata)

        return InvokeServiceResponse(
            response.data, response.content_type,
            call.initial_metadata(), call.trailing_metadata())
github dapr / python-sdk / examples / invoke-custom-data / invoke-caller.py View on Github external
import proto.response_pb2 as response_messages

from google.protobuf.any_pb2 import Any

# Start a gRPC client
port = os.getenv('DAPR_GRPC_PORT')
channel = grpc.insecure_channel(f"localhost:{port}")
client = api_service_v1.DaprStub(channel)
print(f"Started gRPC client on DAPR_GRPC_PORT: {port}")

# Invoke the Receiver

req = api_v1.InvokeServiceRequest(
    id="invoke-receiver",
    message=common_v1.InvokeRequest(
        method='my_method',
        data=Any(value='SOME_DATA'.encode('utf-8')),
        content_type="text/plain; charset=UTF-8")
)
response = client.InvokeService(req)

# Unpack the response
res = response_messages.CustomResponse()
if response.data.Is(response_messages.CustomResponse.DESCRIPTOR):
    response.data.Unpack(res)
    print("test", flush=True)

# Print Result
print(res, flush=True)

channel.close()