コード例 #1
0
 /// <summary>
 /// Execute tryGetMessage and wait for result
 ///     On success, process message
 ///     On fail, notify observers of failure
 ///
 /// </summary>
 /// <param name="message"></param>
 /// <param name="token"></param>
 /// <param name="scheduler"></param>
 /// <returns></returns>
 Unit QueueForProcessing(BrokerMessage message, CancellationToken token, TaskScheduler scheduler) =>
 unit.Tap(_ => _workers.Enqueue(
              Task.Factory.StartNew(() =>
                                    IsAsync
             ? _composeProcessMessageAsync.Match(
                                        some: compose =>
                                        map(compose(token, _observers), processMessage =>
                                            processMessage(message)
                                            .Match(
                                                success: __ => unit,
                                                fail: exception => ProcessException(exception, message, token, _scheduler)).Result),
                                        none: () => unit)
             : _composeProcessMessage.Match(
                                        some: compose =>
                                        map(compose(token, _observers), processMessage =>
                                            processMessage(message).Match(
                                                right: __ => unit,
                                                left: exception => ProcessException(exception, message, token, _scheduler))),
                                        none: () => unit),
                                    token, TaskCreationOptions.None, scheduler)
              .ContinueWith(TaskContinuation, token)));
コード例 #2
0
            Task <BrokerMessage> > RunReceiveCommandFactory() => async(log, executeNonQueryAsync, command) =>
        {
            var message = BrokerMessage.Empty;
            var result  = await executeNonQueryAsync(command);

            var parameters = command.Parameters;

            if (!(parameters[0].AsSqlParameter().Value is DBNull))
            {
                log.Debug(command.ToLogString(nameof(RunReceiveCommandFactory)));

                message = new BrokerMessage(
                    parameters[0].AsSqlParameter().Value.ToString(),
                    parameters[1].AsSqlParameter().Value.ToString(),
                    parameters[2].AsSqlParameter().Value.ToString(),
                    (Guid)parameters[3].AsSqlParameter().Value,
                    (Guid)parameters[4].AsSqlParameter().Value);
            }

            return(message);
        };
コード例 #3
0
ファイル: AppPrelude.cs プロジェクト: PSNS-IMF/clients-broker
 /// <summary>
 /// Adds error handling to IObserver.OnNext
 /// </summary>
 /// <param name="self"></param>
 /// <param name="next"></param>
 /// <param name="logger"></param>
 /// <returns></returns>
 public static Unit SendNext(this IBrokerObserver self, BrokerMessage next, Maybe <Log> logger) =>
 Try(() => self.OnNext(next)).Match(
     _ => _,
     e => self.SendError(logger.Debug(e, $"{nameof(self.OnNext)} failed. Calling {nameof(self.OnError)}"), next, logger));
コード例 #4
0
 public static Try <string> AsJson(this BrokerMessage self) => () =>
 JsonConvert.SerializeObject(self, Formatting.Indented);
コード例 #5
0
 public static BrokerMessage WithContract(this BrokerMessage self, string contract) =>
 new BrokerMessage(contract, self.MessageType, self.Message, self.ConversationGroup, self.Conversation);
コード例 #6
0
 public static BrokerMessage WithType(this BrokerMessage self, string messageType) =>
 new BrokerMessage(self.Contract, messageType, self.Message, self.ConversationGroup, self.Conversation);
コード例 #7
0
 /// <summary>
 /// Send a <see cref="BrokerMessage"/>.
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public Either <Exception, Unit> Send(BrokerMessage message) =>
 SendFactory()(_logger, _connectionFactory, message);