static void Main(string[] args) { ECommonConfiguration .Create() .UseAutofac() .RegisterCommonComponents() .UseLog4Net() .RegisterUnhandledExceptionHandler(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(typeof(Program).Name); var serverIP = ConfigurationManager.AppSettings["ServerAddress"]; var mode = ConfigurationManager.AppSettings["Mode"]; var serverAddress = string.IsNullOrEmpty(serverIP) ? SocketUtils.GetLocalIPV4() : IPAddress.Parse(serverIP); var parallelThreadCount = int.Parse(ConfigurationManager.AppSettings["ClientCount"]); var messageSize = int.Parse(ConfigurationManager.AppSettings["MessageSize"]); var messageCount = int.Parse(ConfigurationManager.AppSettings["MessageCount"]); var sleepMilliseconds = int.Parse(ConfigurationManager.AppSettings["SleepMilliseconds"]); var batchSize = int.Parse(ConfigurationManager.AppSettings["BatchSize"]); var message = new byte[messageSize]; var actions = new List <Action>(); for (var i = 0; i < parallelThreadCount; i++) { var client = new SocketRemotingClient(new IPEndPoint(serverAddress, 5000)); client.Start(); actions.Add(() => SendMessages(client, mode, messageCount, sleepMilliseconds, batchSize, message)); } _watch.Start(); Parallel.Invoke(actions.ToArray()); Console.ReadLine(); }
public Consumer(string groupName, ConsumerSetting setting) { if (groupName == null) { throw new ArgumentNullException("groupName"); } GroupName = groupName; Setting = setting ?? new ConsumerSetting(); _lockObject = new object(); _subscriptionTopics = new List <string>(); _topicQueuesDict = new ConcurrentDictionary <string, IList <MessageQueue> >(); _pullRequestQueue = new BlockingCollection <PullRequest>(new ConcurrentQueue <PullRequest>()); _pullRequestDict = new ConcurrentDictionary <string, PullRequest>(); _messageRetryQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>()); _taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount)); _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress); _adminRemotingClient = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>(); _executePullRequestWorker = new Worker("ExecutePullRequest", ExecutePullRequest); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this)); }
private BrokerConnection BuildAndStartBrokerConnection(BrokerInfo brokerInfo) { IPEndPoint brokerEndpoint; if (_producer != null) { brokerEndpoint = brokerInfo.ProducerAddress.ToEndPoint(); } else if (_consumer != null) { brokerEndpoint = brokerInfo.ConsumerAddress.ToEndPoint(); } else { throw new Exception("ClientService must set producer or consumer."); } var brokerAdminEndpoint = brokerInfo.AdminAddress.ToEndPoint(); var remotingClient = new SocketRemotingClient(_setting.ClientName, brokerEndpoint, _setting.SocketSetting); var adminRemotingClient = new SocketRemotingClient(_setting.ClientName, brokerAdminEndpoint, _setting.SocketSetting); var brokerConnection = new BrokerConnection(brokerInfo, remotingClient, adminRemotingClient); if (_producer != null && _producer.ResponseHandler != null) { remotingClient.RegisterResponseHandler((int)BrokerRequestCode.SendMessage, _producer.ResponseHandler); remotingClient.RegisterResponseHandler((int)BrokerRequestCode.BatchSendMessage, _producer.ResponseHandler); } brokerConnection.Start(); return(brokerConnection); }
public Consumer(string id, string groupName, ConsumerSetting setting) { if (id == null) { throw new ArgumentNullException("id"); } if (groupName == null) { throw new ArgumentNullException("groupName"); } Id = id; GroupName = groupName; Setting = setting ?? new ConsumerSetting(); _lockObject = new object(); _subscriptionTopics = new List <string>(); _topicQueuesDict = new ConcurrentDictionary <string, IList <MessageQueue> >(); _pullRequestQueue = new BlockingCollection <PullRequest>(new ConcurrentQueue <PullRequest>()); _pullRequestDict = new ConcurrentDictionary <string, PullRequest>(); _consumingMessageQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>()); _messageRetryQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>()); _handlingMessageDict = new ConcurrentDictionary <long, ConsumingMessage>(); _taskIds = new List <int>(); _taskFactory = new TaskFactory(new LimitedConcurrencyLevelTaskScheduler(Setting.ConsumeThreadMaxCount)); _remotingClient = new SocketRemotingClient(Setting.BrokerConsumerIPEndPoint, null, this); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>(); _executePullRequestWorker = new Worker("Consumer.ExecutePullRequest", ExecutePullRequest); _handleMessageWorker = new Worker("Consumer.HandleMessage", HandleMessage); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); _waitSocketConnectHandle = new AutoResetEvent(false); }
static void SendMessages(SocketRemotingClient client, string mode, int count, int sleepMilliseconds, int batchSize, byte[] message) { Console.WriteLine("----Send message test----"); if (mode == "Oneway") { for (var i = 1; i <= count; i++) { TryAction(() => client.InvokeOneway(new RemotingRequest(100, message))); var current = Interlocked.Increment(ref _totalReceivedCount); if (current % 10000 == 0) { Console.WriteLine("Sent {0} messages, timeSpent: {1}ms", current, _watch.ElapsedMilliseconds); } WaitIfNecessory(batchSize, sleepMilliseconds); } } else if (mode == "Async") { for (var i = 1; i <= count; i++) { TryAction(() => client.InvokeAsync(new RemotingRequest(100, message), 100000).ContinueWith(SendCallback)); WaitIfNecessory(batchSize, sleepMilliseconds); } } else if (mode == "Callback") { client.RegisterResponseHandler(100, new ResponseHandler()); for (var i = 1; i <= count; i++) { TryAction(() => client.InvokeWithCallback(new RemotingRequest(100, message))); WaitIfNecessory(batchSize, sleepMilliseconds); } } }
public Consumer(string groupName, ConsumerSetting setting) { if (groupName == null) { throw new ArgumentNullException("groupName"); } GroupName = groupName; Setting = setting ?? new ConsumerSetting(); _lockObject = new object(); _subscriptionTopics = new Dictionary <string, HashSet <string> >(); _topicQueuesDict = new ConcurrentDictionary <string, IList <MessageQueue> >(); _pullRequestDict = new ConcurrentDictionary <string, PullRequest>(); _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress); _adminRemotingClient = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); _adminRemotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this)); if (Setting.MessageHandleMode == MessageHandleMode.Sequential) { _consumingMessageQueue = new BlockingCollection <ConsumingMessage>(); _consumeMessageWorker = new Worker("ConsumeMessage", () => HandleMessage(_consumingMessageQueue.Take())); } _messageRetryQueue = new BlockingCollection <ConsumingMessage>(); }
private void RegisterBrokerToNameServer(BrokerRegistrationRequest request, SocketRemotingClient remotingClient, bool isSync = false) { var nameServerAddress = remotingClient.ServerEndPoint.ToAddress(); try { var data = _binarySerializer.Serialize(request); var remotingRequest = new RemotingRequest((int)NameServerRequestCode.RegisterBroker, data); if (isSync) { var response = remotingClient.InvokeSync(remotingRequest, 10000); if (response.ResponseCode != ResponseCode.Success) { throw new Exception("Register broker to name server failed."); } } else { remotingClient.InvokeOneway(remotingRequest); } } catch (Exception ex) { _logger.Error(string.Format("Register broker to name server has exception, brokerInfo: {0}, nameServerAddress: {1}", request.BrokerInfo, nameServerAddress), ex); } }
public Consumer(string id, string groupName, ConsumerSetting setting) { if (id == null) { throw new ArgumentNullException("id"); } if (groupName == null) { throw new ArgumentNullException("groupName"); } Id = id; GroupName = groupName; Setting = setting ?? new ConsumerSetting(); _lockObject = new object(); _subscriptionTopics = new List <string>(); _topicQueuesDict = new ConcurrentDictionary <string, IList <MessageQueue> >(); _pullRequestQueue = new BlockingCollection <PullRequest>(new ConcurrentQueue <PullRequest>()); _pullRequestDict = new ConcurrentDictionary <string, PullRequest>(); _consumingMessageQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>()); _messageRetryQueue = new BlockingCollection <ConsumingMessage>(new ConcurrentQueue <ConsumingMessage>()); _handlingMessageDict = new ConcurrentDictionary <long, ConsumingMessage>(); _taskIds = new List <int>(); _taskFactory = new TaskFactory(); _remotingClient = new SocketRemotingClient(string.Format("{0}.RemotingClient", Id), Setting.BrokerAddress, Setting.LocalAddress); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>(); _executePullRequestWorker = new Worker(string.Format("{0}.ExecutePullRequest", Id), ExecutePullRequest); _handleMessageWorker = new Worker(string.Format("{0}.HandleMessage", Id), HandleMessage); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this)); }
private SocketRemotingClient CreateClient() { SocketRemotingClient client = new SocketRemotingClient(IPEndPoint); client.RegisterConnectionEventListener(new ClientPoolConnectionLister(client, this)); Interlocked.Increment(ref PrepareCreateCount); client.Start(); return(client); }
public MessageService(IBinarySerializer binarySerializer, IScheduleService scheduleService, SendEmailService sendEmailService) { _remotingClient = new SocketRemotingClient(Settings.BrokerAddress); _binarySerializer = binarySerializer; _scheduleService = scheduleService; _unconsumedMessageWarnningThreshold = int.Parse(ConfigurationManager.AppSettings["unconsumedMessageWarnningThreshold"]); _checkUnconsumedMessageInterval = int.Parse(ConfigurationManager.AppSettings["checkUnconsumedMessageInterval"]); _sendEmailService = sendEmailService; }
static void Main(string[] args) { Configuration .Create() .UseAutofac() .RegisterCommonComponents() .UseLog4Net(); var clientCount = 4; var clients = new List <SocketRemotingClient>(); var messageSize = 1024; var messageCount = 250000; var message = new byte[messageSize]; var totalSent = 0; var watch = default(Stopwatch); for (var index = 0; index < clientCount; index++) { var client = new SocketRemotingClient("Client", new IPEndPoint(SocketUtils.GetLocalIPV4(), 5000)); client.Start(); clients.Add(client); } var actions = new List <Action>(); foreach (var client in clients) { actions.Add(() => { for (var i = 0; i < messageCount; i++) { client.InvokeAsync(new RemotingRequest(100, message), 100000000).ContinueWith(task => { if (task.Exception != null) { Console.WriteLine("sent has exception, errorMsg:{0}", task.Exception.InnerExceptions[0].Message); return; } var local = Interlocked.Increment(ref totalSent); if (local == 1) { watch = Stopwatch.StartNew(); } if (local % 10000 == 0) { Console.WriteLine("handle response, size:" + task.Result.Body.Length + ", count:" + local + ", timeSpent:" + watch.ElapsedMilliseconds + "ms"); } }); } }); } Parallel.Invoke(actions.ToArray()); Console.ReadLine(); }
public static IEnumerable <SocketRemotingClient> ToRemotingClientList(this IEnumerable <IPEndPoint> endpointList, SocketSetting socketSetting) { var remotingClientList = new List <SocketRemotingClient>(); foreach (var endpoint in endpointList) { var remotingClient = new SocketRemotingClient(endpoint, socketSetting); remotingClientList.Add(remotingClient); } return(remotingClientList); }
private IList <SocketRemotingClient> CreateRemotingClientList(IEnumerable <IPEndPoint> endpointList) { var remotingClientList = new List <SocketRemotingClient>(); foreach (var endpoint in endpointList) { var remotingClient = new SocketRemotingClient("EQueueWebAdminSocketRemotingClient", endpoint, _eQueueSettingService.SocketSetting); remotingClientList.Add(remotingClient); } return(remotingClientList); }
private IList <SocketRemotingClient> CreateRemotingClientList(IEnumerable <IPEndPoint> endpointList) { var remotingClientList = new List <SocketRemotingClient>(); foreach (var endpoint in endpointList) { var remotingClient = new SocketRemotingClient(endpoint, Settings.SocketSetting); remotingClientList.Add(remotingClient); } return(remotingClientList); }
private SocketRemotingClientWrapper CreateReplyRemotingClient(IPEndPoint replyEndpoint) { return(_sendReplyRemotingClientDict.GetOrAdd(replyEndpoint.ToString(), key => { var remotingClient = new SocketRemotingClient(replyEndpoint).Start(); return new SocketRemotingClientWrapper { ReplyEndpoint = replyEndpoint, RemotingClient = remotingClient, LastActiveTime = DateTime.Now }; })); }
public Producer(ProducerSetting setting) { Setting = setting ?? new ProducerSetting(); _topicQueueIdsDict = new ConcurrentDictionary <string, IList <int> >(); _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.SocketSetting, Setting.LocalAddress); _adminRemotingClient = new SocketRemotingClient(Setting.BrokerAdminAddress, Setting.SocketSetting, Setting.LocalAdminAddress); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _queueSelector = ObjectContainer.Resolve <IQueueSelector>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this)); }
private IEnumerable <int> CreateTopicOnBroker(string topic, Broker broker) { var brokerAdminEndpoint = broker.BrokerInfo.AdminAddress.ToEndPoint(); var adminRemotingClient = new SocketRemotingClient(brokerAdminEndpoint, _nameServerController.Setting.SocketSetting).Start(); var requestData = _binarySerializer.Serialize(new CreateTopicRequest(topic)); var remotingRequest = new RemotingRequest((int)BrokerRequestCode.CreateTopic, requestData); var remotingResponse = adminRemotingClient.InvokeSync(remotingRequest, 30000); if (remotingResponse.ResponseCode != ResponseCode.Success) { throw new Exception(string.Format("AutoCreateTopicOnBroker failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody))); } adminRemotingClient.Shutdown(); return(_binarySerializer.Deserialize <IEnumerable <int> >(remotingResponse.ResponseBody)); }
static void InitializeECommon() { ECommonConfiguration .Create() .UseAutofac() .RegisterCommonComponents() .UseLog4Net() .RegisterUnhandledExceptionHandler(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(typeof(Program).Name); var serverIP = ConfigurationManager.AppSettings["ServerAddress"]; var serverAddress = string.IsNullOrEmpty(serverIP) ? SocketUtils.GetLocalIPV4() : IPAddress.Parse(serverIP); _client = new SocketRemotingClient(new IPEndPoint(serverAddress, 5000)).Start(); _client.RegisterRemotingServerMessageHandler(100, new RemotingServerMessageHandler()); }
public Producer(string id, ProducerSetting setting) { if (id == null) { throw new ArgumentNullException("id"); } Id = id; Setting = setting ?? new ProducerSetting(); _topicQueueCountDict = new ConcurrentDictionary <string, int>(); _taskIds = new List <int>(); _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.BrokerPort); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _queueSelector = ObjectContainer.Resolve <IQueueSelector>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); }
public Producer(string id, ProducerSetting setting) { if (id == null) { throw new ArgumentNullException("id"); } Id = id; Setting = setting ?? new ProducerSetting(); _lockObject = new object(); _taskIds = new List <int>(); _topicQueueIdsDict = new ConcurrentDictionary <string, IList <int> >(); _remotingClient = new SocketRemotingClient(Setting.BrokerProducerIPEndPoint, null, this); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _queueSelector = ObjectContainer.Resolve <IQueueSelector>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); }
static void Main(string[] args) { Configuration .Create() .UseAutofac() .RegisterCommonComponents() .UseLog4Net() .RegisterUnhandledExceptionHandler(); _remotingClient = new SocketRemotingClient(new IPEndPoint(SocketUtils.GetLocalIPV4(), 5000)); _remotingClient.Start(); SendMessageSync(); SendMessageAsync(); Console.ReadLine(); }
public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration) { var brokerStorePath = ConfigurationManager.AppSettings["equeue-store-path"]; if (Directory.Exists(brokerStorePath)) { Directory.Delete(brokerStorePath, true); } _commandService.InitializeEQueue(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001))); _applicationMessagePublisher.InitializeEQueue(); _domainEventPublisher.InitializeEQueue(); _exceptionPublisher.InitializeEQueue(); _nameServerController = new NameServerController(); _broker = BrokerController.Create(new BrokerSetting(chunkFileStoreRootPath: brokerStorePath)); _commandConsumer = new CommandConsumer().InitializeEQueue().Subscribe(Constants.CommandTopic); _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeEQueue().Subscribe(Constants.ApplicationMessageTopic); _eventConsumer = new DomainEventConsumer().InitializeEQueue().Subscribe(Constants.EventTopic); _exceptionConsumer = new DomainExceptionConsumer().InitializeEQueue().Subscribe(Constants.ExceptionTopic); _nameServerSocketRemotingClient = new SocketRemotingClient("NameServerRemotingClient", new IPEndPoint(SocketUtils.GetLocalIPV4(), 9493)); _nameServerController.Start(); _broker.Start(); _exceptionConsumer.Start(); _eventConsumer.Start(); _applicationMessageConsumer.Start(); _commandConsumer.Start(); _applicationMessagePublisher.Start(); _domainEventPublisher.Start(); _exceptionPublisher.Start(); _commandService.Start(); _nameServerSocketRemotingClient.Start(); //生产环境不需要以下这段代码 CreateTopic(Constants.CommandTopic); CreateTopic(Constants.EventTopic); CreateTopic(Constants.ApplicationMessageTopic); CreateTopic(Constants.ExceptionTopic); WaitAllProducerTopicQueuesAvailable(); WaitAllConsumerLoadBalanceComplete(); return(enodeConfiguration); }
public Producer(string id, ProducerSetting setting) { if (id == null) { throw new ArgumentNullException("id"); } Id = id; Setting = setting ?? new ProducerSetting(); _lockObject = new object(); _topicQueueIdsDict = new ConcurrentDictionary <string, IList <int> >(); _remotingClient = new SocketRemotingClient(Id + ".RemotingClient", Setting.BrokerAddress, Setting.LocalAddress); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _queueSelector = ObjectContainer.Resolve <IQueueSelector>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); _remotingClient.RegisterConnectionEventListener(new ConnectionEventListener(this)); }
private void RegisterBrokerToNameServer(BrokerRegistrationRequest request, SocketRemotingClient remotingClient) { var nameServerAddress = remotingClient.ServerEndPoint.ToAddress(); try { var data = _binarySerializer.Serialize(request); var remotingRequest = new RemotingRequest((int)NameServerRequestCode.RegisterBroker, data); var remotingResponse = remotingClient.InvokeSync(remotingRequest, 5 * 1000); if (remotingResponse.ResponseCode != ResponseCode.Success) { _logger.Error(string.Format("Register broker to name server failed, brokerInfo: {0}, nameServerAddress: {1}, remoting response code: {2}, errorMessage: {3}", request.BrokerInfo, nameServerAddress, remotingResponse.ResponseCode, Encoding.UTF8.GetString(remotingResponse.ResponseBody))); } } catch (Exception ex) { _logger.Error(string.Format("Register broker to name server has exception, brokerInfo: {0}, nameServerAddress: {1}", request.BrokerInfo, nameServerAddress), ex); } }
public Consumer(string id, string groupName, ConsumerSetting setting) { if (id == null) { throw new ArgumentNullException("id"); } if (groupName == null) { throw new ArgumentNullException("groupName"); } Id = id; GroupName = groupName; Setting = setting ?? new ConsumerSetting(); _remotingClient = new SocketRemotingClient(Setting.BrokerAddress, Setting.BrokerPort); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _scheduleService = ObjectContainer.Resolve <IScheduleService>(); _localOffsetStore = ObjectContainer.Resolve <ILocalOffsetStore>(); _allocateMessageQueueStragegy = ObjectContainer.Resolve <IAllocateMessageQueueStrategy>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); }
public PullRequest( string consumerId, string groupName, MessageQueue messageQueue, long queueOffset, SocketRemotingClient remotingClient, MessageHandleMode messageHandleMode, IMessageHandler messageHandler, PullRequestSetting setting) { ConsumerId = consumerId; GroupName = groupName; MessageQueue = messageQueue; ProcessQueue = new ProcessQueue(); _queueOffset = queueOffset; _remotingClient = remotingClient; _setting = setting; _messageHandleMode = messageHandleMode; _messageHandler = messageHandler; _messageQueue = new BlockingCollection <WrappedMessage>(new ConcurrentQueue <WrappedMessage>()); _handlingMessageDict = new ConcurrentDictionary <long, WrappedMessage>(); _pullMessageWorker = new Worker(() => { try { PullMessage(); } catch (Exception ex) { if (!_stoped) { _logger.Error(string.Format("PullMessage has unknown exception, pullRequest:{0}.", this), ex); } } }); _handleMessageWorker = new Worker(HandleMessage); _binarySerializer = ObjectContainer.Resolve <IBinarySerializer>(); _logger = ObjectContainer.Resolve <ILoggerFactory>().Create(GetType().FullName); }
private void RefreshClusterBrokers(string clusterName) { var remotingClient = GetAvailableNameServerRemotingClient(); var requestData = _binarySerializer.Serialize(new GetClusterBrokersRequest { ClusterName = clusterName }); var remotingRequest = new RemotingRequest((int)NameServerRequestCode.GetClusterBrokers, requestData); var remotingResponse = remotingClient.InvokeSync(remotingRequest, 30000); if (remotingResponse.ResponseCode == ResponseCode.Success) { var brokerInfoList = _binarySerializer.Deserialize <IEnumerable <BrokerInfo> >(remotingResponse.ResponseBody); var brokerClientList = new List <BrokerClient>(); foreach (var brokerInfo in brokerInfoList) { var client = new SocketRemotingClient(brokerInfo.AdminAddress.ToEndPoint(), Settings.SocketSetting).Start(); var brokerClient = new BrokerClient { BrokerInfo = brokerInfo, RemotingClient = client }; brokerClientList.Add(brokerClient); } IList <BrokerClient> removedList; if (_clusterBrokerDict.TryRemove(clusterName, out removedList)) { foreach (var brokerClient in removedList) { brokerClient.RemotingClient.Shutdown(); } } _clusterBrokerDict.TryAdd(clusterName, brokerClientList); } else { throw new Exception(string.Format("GetClusterBrokers failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody))); } }
public ClientPoolConnectionLister(SocketRemotingClient client, ClientPool clientPool) { _client = client; _clientPool = clientPool; _lock = DependencyManage.Resolve <ILock>(); }
public BrokerConnection(BrokerInfo brokerInfo, SocketRemotingClient adminRemotingClient) { _brokerInfo = brokerInfo; _adminRemotingClient = adminRemotingClient; }
public static ENodeConfiguration StartEQueue(this ENodeConfiguration enodeConfiguration) { if (_isEQueueStarted) { _commandService.InitializeENode(); _eventPublisher.InitializeENode(); _applicationMessagePublisher.InitializeENode(); _domainExceptionPublisher.InitializeENode(); _commandConsumer.InitializeENode(); _eventConsumer.InitializeENode(); _applicationMessageConsumer.InitializeENode(); _domainExceptionConsumer.InitializeENode(); return(enodeConfiguration); } var brokerStorePath = @"d:\equeue-store-enode-ut"; var brokerSetting = new BrokerSetting(chunkFileStoreRootPath: brokerStorePath); if (Directory.Exists(brokerStorePath)) { Directory.Delete(brokerStorePath, true); } _nameServerController = new NameServerController(); _broker = BrokerController.Create(brokerSetting); _commandService.InitializeEQueue(new CommandResultProcessor().Initialize(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001))); _eventPublisher.InitializeEQueue(); _applicationMessagePublisher.InitializeEQueue(); _domainExceptionPublisher.InitializeEQueue(); _commandConsumer = new CommandConsumer().InitializeEQueue(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.LastOffset }).Subscribe("CommandTopic"); _eventConsumer = new DomainEventConsumer().InitializeEQueue(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.LastOffset }).Subscribe("EventTopic"); _applicationMessageConsumer = new ApplicationMessageConsumer().InitializeEQueue(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.LastOffset }).Subscribe("ApplicationMessageTopic"); _domainExceptionConsumer = new DomainExceptionConsumer().InitializeEQueue(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.LastOffset }).Subscribe("DomainExceptionTopic"); _nameServerSocketRemotingClient = new SocketRemotingClient("NameServerRemotingClient", new IPEndPoint(SocketUtils.GetLocalIPV4(), 9493)); _nameServerController.Start(); _broker.Start(); _eventConsumer.Start(); _commandConsumer.Start(); _applicationMessageConsumer.Start(); _domainExceptionConsumer.Start(); _applicationMessagePublisher.Start(); _domainExceptionPublisher.Start(); _eventPublisher.Start(); _commandService.Start(); _nameServerSocketRemotingClient.Start(); CreateTopic(Constants.CommandTopic); CreateTopic(Constants.EventTopic); CreateTopic(Constants.ApplicationMessageTopic); CreateTopic(Constants.ExceptionTopic); WaitAllProducerTopicQueuesAvailable(); WaitAllConsumerLoadBalanceComplete(); _isEQueueStarted = true; return(enodeConfiguration); }