Beispiel #1
0
 public AzureStorageClient()
 {
     storageAccount     = CloudStorageAccount.Parse(ConfigurationManager.AppSettings["StorageConnectionString"]);
     LoggerClient       = new LoggerClient(storageAccount);
     BlobClient         = new BlobClient(storageAccount);
     MessageQueueClient = new MessageQueueClient(storageAccount);
 }
Beispiel #2
0
        public override void Start()
        {
            base.Start();

            #region init process command reply worker

            try
            {
                if (!string.IsNullOrWhiteSpace(_replyTopicName))
                {
                    _internalConsumer = MessageQueueClient.StartSubscriptionClient(_replyTopicName,
                                                                                   _replySubscriptionName,
                                                                                   _consumerId,
                                                                                   OnMessagesReceived,
                                                                                   _consumerConfig);
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e, $"command bus started faield");
            }

            #endregion

            _messageProcessor.Start();
        }
        protected override async Task SendMessageStateAsync(MessageState messageState, CancellationToken cancellationToken)
        {
            var messageContext = messageState.MessageContext;
            await MessageQueueClient.PublishAsync(messageContext, messageContext.Topic ?? DefaultTopic, cancellationToken);

            CompleteSendingMessage(messageState);
        }
Beispiel #4
0
        protected override async Task SendMessageStateAsync(MessageState messageState, CancellationToken cancellationToken)
        {
            Logger.LogDebug($"send message start msgId: {messageState.MessageID} topic:{messageState.MessageContext.Topic}");
            var messageContext = messageState.MessageContext;
            await MessageQueueClient.SendAsync(messageContext, messageContext.Topic ?? DefaultTopic, cancellationToken);

            Logger.LogDebug($"send message complete msgId: {messageState.MessageID} topic:{messageState.MessageContext.Topic}");
            CompleteSendingMessage(messageState);
        }
 public IHttpActionResult GetHealthStatus()
 {
     return(Ok(new InEngineHealthStatus()
     {
         IsMailServerAvailable = MailClient.IsServerAvailable(),
         IsMessageQueueServerAvailable = MessageQueueClient.IsServerAvailable(),
         IsElasticsearchServerAvailable = Repository.IsServerAvailable(),
     }));
 }
 protected override IEnumerable <IMessageContext> GetAllUnSentMessages()
 {
     using (var scope = ObjectProviderFactory.Instance.ObjectProvider.CreateScope())
         using (var messageStore = scope.GetService <IMessageStore>())
         {
             return(messageStore.GetAllUnPublishedEvents((messageId, message, topic, correlationId, replyEndPoint, sagaInfo, producer) =>
                                                         MessageQueueClient.WrapMessage(message, key: message.Key,
                                                                                        topic: topic, messageId: messageId,
                                                                                        correlationId: correlationId,
                                                                                        replyEndPoint: replyEndPoint,
                                                                                        sagaInfo: sagaInfo, producer: producer)));
         }
 }
Beispiel #7
0
        public static ClientConnectionBase CreateClientConnection(ConnectionTypes conType)
        {
            ClientConnectionBase client = null;

            switch (conType)
            {
            case ConnectionTypes.Sockets:
                client = new SocketClient(SocketHost, SocketPort);
                break;

            case ConnectionTypes.RabbitMQ:
                client = new MessageQueueClient(MQUserName, MQPassword, MQVirtualHost, MQHostName, MQPort, RpcQueueName);
                break;
            }
            return(client);
        }
Beispiel #8
0
        public IMessageContext WrapCommand(ICommand command,
                                           bool needReply,
                                           SagaInfo sagaInfo = null,
                                           string producer   = null)
        {
            if (string.IsNullOrEmpty(command.Id))
            {
                var noMessageIdException = new NoMessageId();
                Logger.LogError(noMessageIdException, $"{command.ToJson()}");
                throw noMessageIdException;
            }
            string commandKey = command.Key;

            if (command is ILinearCommand linearCommand)
            {
                var linearKey = _linearCommandManager.GetLinearKey(linearCommand);
                if (linearKey != null)
                {
                    commandKey  = linearKey.ToString();
                    command.Key = commandKey;
                }
            }
            IMessageContext commandContext = null;

            #region pickup a queue to send command

            // move this logic into  concrete messagequeueClient. kafka sdk already implement it.
            // service bus client still need it.
            //int keyUniqueCode = !string.IsNullOrWhiteSpace(commandKey) ?
            //    commandKey.GetUniqueCode() : command.Id.GetUniqueCode();
            //var queue = _commandQueueNames[Math.Abs(keyUniqueCode % _commandQueueNames.Length)];

            #endregion

            var topic = command.GetFormatTopic();
            commandContext = MessageQueueClient.WrapMessage(command,
                                                            topic: topic,
                                                            key: commandKey,
                                                            replyEndPoint: needReply ? _replyTopicName : null,
                                                            sagaInfo: sagaInfo,
                                                            producer: producer ?? _consumerId);
            if (string.IsNullOrEmpty(commandContext.Topic))
            {
                throw new NoCommandTopic();
            }
            return(commandContext);
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            IMessageQueue client = new MessageQueueClient();

            for (var i = 0; i < 5; i++)
            {
                var s1 = RandomString(5);
                Thread.Sleep(1);
                var s2 = RandomString(5);
                Thread.Sleep(1);
                var s3 = RandomString(5);
                Thread.Sleep(1);
                var s4  = RandomString(5);
                var arr = new object[]
                {
                    s1,
                    s2,
                    s3,
                    s4
                };
                client.AddMassage(RandomString(10), JsonConvert.SerializeObject(arr));
                Thread.Sleep(1000);
            }

            client.RemoveMessage();
            while (true)
            {
                var c = Console.ReadKey();
                switch (c.Key)
                {
                case ConsoleKey.D1:
                    client.Dump();
                    break;

                case ConsoleKey.D2:
                    client.Restore();
                    break;

                case ConsoleKey.D0:
                    return;
                }
            }
        }
Beispiel #10
0
 public void Dispatch <T>(T value, IDictionary <string, string> parameters)
 {
     try
     {
         var type = value.GetType();
         if (type is IParameterizedJob)
         {
             (value as IParameterizedJob).Parameters = parameters;
         }
         var message = JsonConvert.SerializeObject(new DispatchTrigger {
             JobType    = type.FullName,
             Parameters = parameters,
         });
         MessageQueueClient.Publish(Encoding.UTF8.GetBytes(message));
         Log.Debug(x => x("Sent message: {0}", message));
     }
     catch (Exception exception)
     {
         Log.Error(exception);
     }
 }
Beispiel #11
0
        /// <summary>
        /// 初始化客户端代理
        /// </summary>
        private void Init()
        {
            if (m_Inited > 0 || Interlocked.CompareExchange(ref m_Inited, 1, 0) > 0)
            {
                return;
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            //--STEP.1.记录客户端版本信息
            Status = ESBProxyStatus.Init;
            var asm = AssemblyX.Create(System.Reflection.Assembly.GetExecutingAssembly());

            Version = String.Format("{0} v{1} Build {2:yyyy-MM-dd HH:mm:ss}", asm.Name, asm.FileVersion, asm.Compile);
            XTrace.WriteLine(Version);

            //--STEP.2.加载配置文件
            LoadConfig();

            //--STEP.3.连接注册中心
            m_RegistryClient = new RegistryConsumerClient(this);
            m_RegistryClient.Connect();

            //--STEP.4.连接队列中心
            m_MessageQueueClient = new MessageQueueClient(this);
            m_MessageQueueClient.ConnectAsync();

            //--STEP.5.连接缓存中心
            m_CacheManager = new CacheManager(this);
            m_CacheManager.ConnectAsync();


            stopWatch.Stop();
            XTrace.WriteLine("ESBProxy Init 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);;
        }
Beispiel #12
0
        /// <summary>
        /// 初始化客户端代理
        /// </summary>
        private void Init()
        {
            if (m_Inited > 0 || Interlocked.CompareExchange(ref m_Inited, 1, 0) > 0) return;

            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();

            //--STEP.1.记录客户端版本信息
            Status = ESBProxyStatus.Init;
            var asm = AssemblyX.Create(System.Reflection.Assembly.GetExecutingAssembly());
            Version = String.Format("{0} v{1} Build {2:yyyy-MM-dd HH:mm:ss}", asm.Name, asm.FileVersion, asm.Compile);
            XTrace.WriteLine(Version);

            //--STEP.2.加载配置文件
            LoadConfig();

            //--STEP.3.连接注册中心
            m_RegistryClient = new RegistryConsumerClient(this);
            m_RegistryClient.Connect();

            //--STEP.4.连接队列中心
            m_MessageQueueClient = new MessageQueueClient(this);
            m_MessageQueueClient.ConnectAsync();

            //--STEP.5.连接缓存中心
            m_CacheManager = new CacheManager(this);
            m_CacheManager.ConnectAsync();


            stopWatch.Stop();
            XTrace.WriteLine("ESBProxy Init 耗时:{0}ms。", stopWatch.ElapsedMilliseconds); ;
        }