示例#1
0
        /// <summary>
        /// Publish a single event using the KubeMQ.
        /// </summary>
        /// <param name="notification">KubeMQ:Event Class.</param>
        /// <returns>KubeMQ.SDK.csharp.PubSub.Result that contain info regarding event status.</returns>
        public Result SendEvent(Event notification)
        {
            try {
                InnerEvent innerEvent = notification.ToInnerEvent();

                KubeMQGrpc.Result innerResult = GetKubeMQClient().SendEvent(innerEvent, Metadata);

                if (innerResult == null)
                {
                    return(null);
                }

                Result result = new Result(innerResult);

                return(result);
            } catch (RpcException ex) {
                logger.LogError(ex, "Exception in SendEvent");

                throw new RpcException(ex.Status);
            } catch (Exception ex) {
                logger.LogError(ex, "Exception in SendEvent");

                throw new Exception(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// publish a constant stream of events.
        /// </summary>
        /// <param name="notification">KubeMQ:Event Class.</param>
        /// <param name="resultDelegate"></param>
        /// <returns>A task that represents the event request that was sent using the StreamEvent .</returns>
        public async Task StreamEvent(Event notification, ReceiveResultDelegate resultDelegate)
        {
            if (!notification.ReturnResult)
            {
                await StreamEventWithoutResponse(notification);

                return;
            }

            // implement bi-di streams 'SendEventStream (stream Event) returns (stream Result)'
            try
            {
                InnerEvent innerEvent = notification.ToInnerEvent();

                // Send Event via GRPC RequestStream
                await GetKubeMQClient().SendEventsStream(_metadata).RequestStream.WriteAsync(innerEvent);

                // Listen for Async Response (Result)
                using (var call = GetKubeMQClient().SendEventsStream(_metadata))
                {
                    // Wait for Response..
                    await call.ResponseStream.MoveNext(CancellationToken.None);

                    // Received a Response
                    KubeMQGrpc.Result response = call.ResponseStream.Current;

                    // add response to queue
                    _RecivedResults.Post(response);
                    LogResponse(response);
                }

                // send result (response) to end-user
                var resultTask = Task.Run((Func <Task>)(async() =>
                {
                    while (true)
                    {
                        // await for response from queue
                        KubeMQGrpc.Result response = await _RecivedResults.ReceiveAsync();

                        // Convert KubeMQ.Grpc.Result to outer Result
                        Result result = new Result(response);

                        // Activate end-user Receive-Result-Delegate
                        resultDelegate(result);
                    }
                }));
            }
            catch (RpcException ex)
            {
                logger.LogError(ex, "RPC Exception in StreamEvent");

                throw new RpcException(ex.Status);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Exception in StreamEvent");

                throw new Exception(ex.Message);
            }
        }
示例#3
0
 public Result(KubeMQGrpc.Result innerResult)
 {
     EventID = innerResult.EventID;
     Sent    = innerResult.Sent;
     Error   = innerResult.Error;
 }
示例#4
0
 private void LogResponse(KubeMQGrpc.Result response)
 {
     logger.LogInformation($"Sender received 'Result': EventID:'{response.EventID}', Sent:'{response.Sent}', Error:'{response.Error}'");
 }