Přeskočit na hlavní obsah

The 1st method - gRPC Message Consumer

Overview

  • This is the first way of communication:
    • To register consumer and consume events of application domain services using message gateway
    • gRPC API is defined by gRPC protocol
    • The event messages are supported by .NET connectors of platform services using nuget packages

Message Gateway

MessageGateway is platform service encapsulating external communication with message broker to HTTP based technologies, gRPC and Webhooks. It is the only way for external cloud and on-premise services integrated with AVAplace platform.

See more: OIDC/OAuth2 authentication

How to consume gRPC message using message gateway

Consume domain entity released event using message gateway

  • Example - how to consume gRPC message(s):

Registration example (Startup.cs):

using ASOL.MessageGateway.Connector.gRPC.Consumer.Extensions;

services.AddMessageGatewayGrpcConsumer(configuration, configurator =>
{
configurator.Consumer<Example1_MyEntityReleasedEventConsumer>();
// ... other consumers ...
});

Usage example:

using ASOL.Core.Identity;
using ASOL.MessageGateway.Connector.gRPC.Consumer;

private readonly IRuntimeContext _runtimeContext;

/// <summary>
/// Example of common domain event consumer against platform message gateway.
/// This example doesn't contain real implementation, it's only for demonstration purposes.
/// </summary>
[ConsumerDefinition("ASOL.Example1.MyEntityReleased")]
public async Task Consume(Example1_MyEntityReleased myEntityReleased)
{
//(optional) check tenant context of received message (exception is thrown if not available)
_ = _runtimeContext.Security.TenantId;

//(optional) check user context of received message (exception is thrown if not available)
_ = _runtimeContext.Security.UserId;

//... evaluate if event should be processed or ignored

// *** [authenticate +] call endpoint ***
//... get details from domain service or persistence storage using MyEntity identifier

//... process delivered message with retrieved payload
}

Configuration changes of gRPC message consumer

The ASOL.MessageGateway.Connector.gRPC.Consumer nuget package (version 0.0.1.49076-dev) contains breaking changes in MessageGatewayGrpcConsumerClientOptions.
It is strongly recommended to upgrade package to version 0.0.1.52050-dev or 0.0.1.51809-dev at least. Both versions contain the same fixes and differ only in the versions of their dependent libraries. Please choose the one that best fits your current requirements. Important: Please, switch from the single BaseUrl property to the two separate properties GateBaseUrl and ApiBaseUrl, and start using the new gate endpoints as soon as possible across all stages, including DEMO and PROD. Support for legacy gRPC communication URLs has been removed on development stages, except PROD stage. In the production environment, legacy URLs will remain functional without changes until it is confirmed that they are no longer in use.

The communication of REST API and gRPC channel was split into two base URLs due their different requirements:

  • GateBaseUrl - base URL for gRPC full-duplex channel
    • DEMO stage: https://demo-gate.avaplace.com
    • PROD stage: https://prod-gate.avaplace.com
  • ApiBaseUrl - base URL for REST API http(s) calls
    • DEMO stage: https://demo.avaplace.com/api/asol/msggw
    • PROD stage: https://avaplace.com/api/asol/msggw

Usage example - appsettings.json:

  "MessageGatewayGrpcConsumerClientOptions": {
"GateBaseUrl": "https://demo-gate.avaplace.com", // PROD stage: "https://prod-gate.avaplace.com"
"ApiBaseUrl": "https://demo.avaplace.com/api/asol/msggw", // PROD stage: "https://avaplace.com/api/asol/msggw"
"ConsumerCode": "<place your consumerCode here>"
},

See examples: