Beispiel #1
0
        public IEnumerable <string> GetAllClusters()
        {
            var remotingClient   = GetAvailableNameServerRemotingClient();
            var remotingRequest  = new RemotingRequest((int)NameServerRequestCode.GetAllClusters, EmptyBytes);
            var remotingResponse = remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode == ResponseCode.Success)
            {
                return(_binarySerializer.Deserialize <IEnumerable <string> >(remotingResponse.ResponseBody));
            }
            else
            {
                throw new Exception(string.Format("GetAllClusters failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #2
0
        private IEnumerable <int> GetTopicQueueIdsFromServer(string topic)
        {
            var remotingRequest  = new RemotingRequest((int)RequestCode.GetTopicQueueIdsForProducer, Encoding.UTF8.GetBytes(topic));
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                var queueIds = Encoding.UTF8.GetString(remotingResponse.Body);
                return(queueIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)));
            }
            else
            {
                throw new Exception(string.Format("GetTopicQueueIds has exception, producerId:{0}, topic:{1}, remoting response code:{2}", Id, topic, remotingResponse.Code));
            }
        }
Beispiel #3
0
        public QueueMessage GetMessageDetail(string messageId)
        {
            var requestData      = _binarySerializer.Serialize(new GetMessageDetailRequest(messageId));
            var remotingRequest  = new RemotingRequest((int)RequestCode.GetMessageDetail, requestData);
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                return(_binarySerializer.Deserialize <IEnumerable <QueueMessage> >(remotingResponse.Body).SingleOrDefault());
            }
            else
            {
                throw new Exception(string.Format("GetMessageDetail failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body)));
            }
        }
Beispiel #4
0
        public BrokerStatisticInfo QueryBrokerStatisticInfo(string clusterName, string brokerName)
        {
            var remotingClient   = GetBrokerByName(clusterName, brokerName);
            var remotingRequest  = new RemotingRequest((int)BrokerRequestCode.GetBrokerStatisticInfo, new byte[0]);
            var remotingResponse = remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode == ResponseCode.Success)
            {
                return(_binarySerializer.Deserialize <BrokerStatisticInfo>(remotingResponse.ResponseBody));
            }
            else
            {
                throw new Exception(string.Format("QueryBrokerStatisticInfo failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #5
0
        private async Task <IEnumerable <int> > CreateTopicOnBroker(string topic, Broker broker)
        {
            var brokerAdminEndpoint = broker.BrokerInfo.AdminAddress.ToEndPoint();
            var adminRemotingClient = new SocketRemotingClient(_nameServerController.Setting.Name, brokerAdminEndpoint, _nameServerController.Setting.SocketSetting).Start();
            var requestData         = _binarySerializer.Serialize(new CreateTopicRequest(topic));
            var remotingRequest     = new RemotingRequest((int)BrokerRequestCode.CreateTopic, requestData);
            var remotingResponse    = await adminRemotingClient.InvokeAsync(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));
        }
Beispiel #6
0
        public IEnumerable <TopicQueueInfo> GetTopicQueueInfo(string topic)
        {
            var requestData      = _binarySerializer.Serialize(new QueryTopicQueueInfoRequest(topic));
            var remotingRequest  = new RemotingRequest((int)RequestCode.QueryTopicQueueInfo, requestData);
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                return(_binarySerializer.Deserialize <IEnumerable <TopicQueueInfo> >(remotingResponse.Body));
            }
            else
            {
                throw new Exception(string.Format("QueryTopicQueueInfo failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body)));
            }
        }
Beispiel #7
0
        private IEnumerable <int> GetTopicQueueIdsFromServer(string topic)
        {
            var remotingRequest  = new RemotingRequest((int)RequestCode.GetTopicQueueIdsForConsumer, Encoding.UTF8.GetBytes(topic));
            var remotingResponse = _adminRemotingClient.InvokeSync(remotingRequest, Setting.DefaultTimeoutMilliseconds);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                var queueIds = Encoding.UTF8.GetString(remotingResponse.Body);
                return(queueIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)));
            }
            else
            {
                throw new Exception(string.Format("GetTopicQueueIds has exception, group: {0}, topic: {1}, remoting response code: {2}", GroupName, topic, remotingResponse.Code));
            }
        }
Beispiel #8
0
        public IEnumerable <string> GetProducerInfo()
        {
            var remotingRequest  = new RemotingRequest((int)RequestCode.QueryProducerInfo, EmptyBytes);
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 10000);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                var producerIds = Encoding.UTF8.GetString(remotingResponse.Body);
                return(producerIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            }
            else
            {
                throw new Exception(string.Format("GetProducerInfo failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body)));
            }
        }
Beispiel #9
0
        public void DeleteConsumerGroup(string consumerGroup)
        {
            if (string.IsNullOrEmpty(consumerGroup))
            {
                throw new ArgumentException("consumerGroup cannot be null or empty.");
            }
            var requestData      = _binarySerializer.Serialize(new DeleteConsumerGroupRequest(consumerGroup));
            var remotingRequest  = new RemotingRequest((int)RequestCode.DeleteConsumerGroup, requestData);
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.Code != (int)ResponseCode.Success)
            {
                throw new Exception(string.Format("DeleteConsumerGroup failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body)));
            }
        }
Beispiel #10
0
        public void SetQueueNextConsumeOffset(string consumerGroup, string topic, int queueId, long nextOffset)
        {
            if (nextOffset < 0)
            {
                throw new ArgumentException("nextOffset cannot be small than zero.");
            }
            var requestData      = _binarySerializer.Serialize(new SetQueueNextConsumeOffsetRequest(consumerGroup, topic, queueId, nextOffset));
            var remotingRequest  = new RemotingRequest((int)RequestCode.SetQueueNextConsumeOffset, requestData);
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.Code != (int)ResponseCode.Success)
            {
                throw new Exception(string.Format("SetQueueNextConsumeOffset failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body)));
            }
        }
Beispiel #11
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            if (remotingRequest.Body.Length > _brokerController.Setting.MessageMaxSize)
            {
                throw new Exception("Message size cannot exceed max message size:" + _brokerController.Setting.MessageMaxSize);
            }

            if (BrokerController.Instance.IsCleaning)
            {
                throw new BrokerCleanningException();
            }

            var request = MessageUtils.DecodeSendMessageRequest(remotingRequest.Body);
            var message = request.Message;
            var queueId = request.QueueId;
            var queue   = _queueStore.GetQueue(message.Topic, queueId);

            if (queue == null)
            {
                throw new QueueNotExistException(message.Topic, queueId);
            }

            _messageStore.StoreMessageAsync(queue, message, (record, parameter) =>
            {
                var storeContext = parameter as StoreContext;
                if (record.LogPosition >= 0 && !string.IsNullOrEmpty(record.MessageId))
                {
                    storeContext.Queue.AddMessage(record.LogPosition, record.Tag);
                    storeContext.MessageLogRecord = record;
                    storeContext.Success          = true;
                }
                else
                {
                    storeContext.Success = false;
                }
                _bufferQueue.EnqueueMessage(storeContext);
            }, new StoreContext
            {
                RequestHandlerContext = context,
                RemotingRequest       = remotingRequest,
                Queue = queue,
                SendMessageRequestHandler = this
            }, request.ProducerAddress);

            _tpsStatisticService.AddTopicSendCount(message.Topic, queueId);

            return(null);
        }
Beispiel #12
0
        public void CommitConsumeOffset(MessageQueue messageQueue, long consumeOffset, bool throwIfException = false)
        {
            Ensure.NotNull(messageQueue, "messageQueue");
            Ensure.Nonnegative(consumeOffset, "consumeOffset");

            var brokerConnection = _clientService.GetBrokerConnection(messageQueue.BrokerName);

            if (brokerConnection == null)
            {
                _logger.ErrorFormat("CommitConsumeOffset failed as the target broker connection not found, messageQueue:{0}", messageQueue);
                return;
            }
            var remotingClient = brokerConnection.AdminRemotingClient;

            var request         = new UpdateQueueOffsetRequest(_consumer.GroupName, messageQueue, consumeOffset);
            var remotingRequest = new RemotingRequest((int)BrokerRequestCode.UpdateQueueConsumeOffsetRequest, _binarySerializer.Serialize(request));
            var brokerAddress   = remotingClient.ServerEndPoint.ToAddress();

            try
            {
                remotingClient.InvokeOneway(remotingRequest);
                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("CommitConsumeOffset success, consumerGroup:{0}, consumerId:{1}, messageQueue:{2}, consumeOffset:{3}, brokerAddress:{4}",
                                        _consumer.GroupName,
                                        _clientId,
                                        messageQueue,
                                        consumeOffset,
                                        brokerAddress);
                }
            }
            catch (Exception ex)
            {
                if (remotingClient.IsConnected)
                {
                    _logger.Error(string.Format("CommitConsumeOffset has exception, consumerGroup:{0}, consumerId:{1}, messageQueue:{2}, consumeOffset:{3}, brokerAddress:{4}",
                                                _consumer.GroupName,
                                                _clientId,
                                                messageQueue,
                                                consumeOffset,
                                                brokerAddress), ex);
                }
                if (throwIfException)
                {
                    throw;
                }
            }
        }
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest request)
        {
            var queryConsumerRequest = _binarySerializer.Deserialize <QueryConsumerRequest>(request.Body);
            var consumerGroup        = _brokerController.ConsumerManager.GetConsumerGroup(queryConsumerRequest.GroupName);
            var consumerIdList       = new List <string>();

            if (consumerGroup != null)
            {
                consumerIdList = consumerGroup.GetConsumerIdsForTopic(queryConsumerRequest.Topic).ToList();
                consumerIdList.Sort();
            }
            var consumerIds = string.Join(",", consumerIdList);
            var data        = Encoding.UTF8.GetBytes(consumerIds);

            return(new RemotingResponse((int)ResponseCode.Success, request.Sequence, data));
        }
Beispiel #14
0
        public void AddQueue(string clusterName, string topic)
        {
            var remotingClient = GetAvailableNameServerRemotingClient();
            var requestData    = _binarySerializer.Serialize(new AddQueueForClusterRequest
            {
                ClusterName = clusterName,
                Topic       = topic
            });
            var remotingRequest  = new RemotingRequest((int)NameServerRequestCode.AddQueue, requestData);
            var remotingResponse = remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode != ResponseCode.Success)
            {
                throw new Exception(string.Format("AddQueue failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #15
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            if (BrokerController.Instance.IsCleaning)
            {
                return(null);
            }

            var request = _binarySerializer.Deserialize <byte[], UpdateQueueOffsetRequest>(remotingRequest.Body);

            _offsetStore.UpdateConsumeOffset(
                request.MessageQueue.Topic,
                request.MessageQueue.QueueId,
                request.QueueOffset,
                request.ConsumerGroup);
            return(null);
        }
Beispiel #16
0
        public async Task <IEnumerable <string> > GetProducerInfoList(string clusterName, string brokerName)
        {
            var remotingClient   = GetBrokerByName(clusterName, brokerName);
            var remotingRequest  = new RemotingRequest((int)BrokerRequestCode.GetProducerList, EmptyBytes);
            var remotingResponse = await remotingClient.InvokeAsync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode == ResponseCode.Success)
            {
                var producerIds = Encoding.UTF8.GetString(remotingResponse.ResponseBody);
                return(producerIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            }
            else
            {
                throw new Exception(string.Format("GetProducerInfo failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #17
0
        public IEnumerable <string> GetLatestSendMessagesList(string clusterName, string brokerName)
        {
            var remotingClient   = GetBrokerByName(clusterName, brokerName);
            var remotingRequest  = new RemotingRequest((int)BrokerRequestCode.GetLastestMessages, EmptyBytes);
            var remotingResponse = remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode == ResponseCode.Success)
            {
                var messageIds = Encoding.UTF8.GetString(remotingResponse.ResponseBody);
                return(messageIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            }
            else
            {
                throw new Exception(string.Format("GetLatestSendMessagesList failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #18
0
        public IEnumerable <ConsumerInfo> GetConsumerInfoList(string clusterName, string brokerName, string group, string topic)
        {
            var remotingClient   = GetBrokerByName(clusterName, brokerName);
            var requestData      = _binarySerializer.Serialize(new Protocols.Brokers.Requests.GetConsumerListRequest(group, topic));
            var remotingRequest  = new RemotingRequest((int)BrokerRequestCode.GetConsumerList, requestData);
            var remotingResponse = remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode == ResponseCode.Success)
            {
                return(_binarySerializer.Deserialize <IEnumerable <ConsumerInfo> >(remotingResponse.ResponseBody));
            }
            else
            {
                throw new Exception(string.Format("GetConsumerInfo failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #19
0
        public QueryMessageResponse QueryMessages(string topic, int?queueId, int?code, string routingKey, int pageIndex, int pageSize)
        {
            var request          = new QueryMessageRequest(topic, queueId, code, routingKey, pageIndex, pageSize);
            var requestData      = _binarySerializer.Serialize(request);
            var remotingRequest  = new RemotingRequest((int)RequestCode.QueryMessage, requestData);
            var remotingResponse = _remotingClient.InvokeSync(remotingRequest, 30000);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                return(_binarySerializer.Deserialize <QueryMessageResponse>(remotingResponse.Body));
            }
            else
            {
                throw new Exception(string.Format("QueryMessages failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.Body)));
            }
        }
Beispiel #20
0
        private IEnumerable <string> QueryGroupConsumers(string topic)
        {
            var queryConsumerRequest = _binarySerializer.Serialize(new QueryConsumerRequest(GroupName, topic));
            var remotingRequest      = new RemotingRequest((int)RequestCode.QueryGroupConsumer, queryConsumerRequest);
            var remotingResponse     = _remotingClient.InvokeSync(remotingRequest, Setting.DefaultTimeoutMilliseconds);

            if (remotingResponse.Code == (int)ResponseCode.Success)
            {
                var consumerIds = Encoding.UTF8.GetString(remotingResponse.Body);
                return(consumerIds.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
            }
            else
            {
                throw new Exception(string.Format("QueryGroupConsumers has exception, consumerId:{0}, group:{1}, topic:{2}, remoting response code:{3}", Id, GroupName, topic, remotingResponse.Code));
            }
        }
Beispiel #21
0
 private static void CreateTopic(string topic)
 {
     var binarySerializer = ObjectContainer.Resolve<IBinarySerializer>();
     var requestData = binarySerializer.Serialize(new CreateTopicForClusterRequest
     {
         ClusterName = "DefaultCluster",
         Topic = topic
     });
     var remotingRequest = new RemotingRequest((int)NameServerRequestCode.CreateTopic, requestData);
     var task = _nameServerSocketRemotingClient.InvokeAsync(remotingRequest, 30000);
     task.Wait();
     if (task.Result.ResponseCode != ResponseCode.Success)
     {
         throw new Exception(string.Format("CreateTopic failed, errorMessage: {0}", Encoding.UTF8.GetString(task.Result.ResponseBody)));
     }
 }
Beispiel #22
0
            public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
            {
                var currentTime = DateTime.Now;

                _performanceService.IncrementKeyCount(_performanceKey, (currentTime - remotingRequest.CreatedTime).TotalMilliseconds);
                return(new RemotingResponse(
                           remotingRequest.Type,
                           remotingRequest.Code,
                           remotingRequest.Sequence,
                           remotingRequest.CreatedTime,
                           10,
                           response,
                           currentTime,
                           remotingRequest.Header,
                           null));
            }
Beispiel #23
0
        public async Task DeleteTopic(string clusterName, string topic)
        {
            var remotingClient = GetAvailableNameServerRemotingClient();
            var requestData    = _binarySerializer.Serialize(new DeleteTopicForClusterRequest
            {
                ClusterName = clusterName,
                Topic       = topic
            });
            var remotingRequest  = new RemotingRequest((int)NameServerRequestCode.DeleteTopic, requestData);
            var remotingResponse = await remotingClient.InvokeAsync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode != ResponseCode.Success)
            {
                throw new Exception(string.Format("DeleteTopic failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #24
0
        public void OnMessage(IReader reader)
        {
            try
            {
                if (closed)
                {
                    logger.Debug($"Got message when closed. Ignoring...");
                    return;
                }

                MessageType       messageType       = (MessageType)reader.ReadByte();
                ReadFormatterInfo readFormatterInfo = new ReadFormatterInfo(reader, rpcSerializer);
                switch (messageType)
                {
                case MessageType.RpcRequest:
                    RemotingRequest remotingRequest = new RemotingRequest();
                    remotingRequest.MergeFrom(readFormatterInfo);
                    LogMessageReceived(remotingRequest);
                    EnqueueRequest(remotingRequest);
                    break;

                case MessageType.RpcResponse:
                    RemotingResponse remotingResponse = new RemotingResponse();
                    remotingResponse.MergeFrom(readFormatterInfo);
                    LogMessageReceived(remotingResponse);
                    ExecuteResponse(remotingResponse);
                    break;

                case MessageType.RpcResponseError:
                    RemotingResponseError remotingResponseError = new RemotingResponseError();
                    remotingResponseError.MergeFrom(readFormatterInfo);
                    LogMessageReceived(remotingResponseError);
                    ExecuteResponseError(remotingResponseError);
                    break;

                default:
                    OnExtraMessage(messageType, readFormatterInfo);
                    break;
                }
            }
            catch (Exception outerException)
            {
                logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnMessage)}(): {outerException}");
                Connection.Close();
            }
        }
Beispiel #25
0
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest request)
        {
            var sendMessageRequest = MessageUtils.DecodeSendMessageRequest(request.Body);
            var storeResult        = _messageService.StoreMessage(sendMessageRequest.Message, sendMessageRequest.QueueId);

            if (_brokerController.Setting.NotifyWhenMessageArrived)
            {
                _brokerController.SuspendedPullRequestManager.NotifyMessageArrived(sendMessageRequest.Message.Topic, storeResult.QueueId, storeResult.QueueOffset);
            }
            var sendMessageResponse = new SendMessageResponse(
                storeResult.MessageOffset,
                new MessageQueue(sendMessageRequest.Message.Topic, storeResult.QueueId),
                storeResult.QueueOffset);
            var responseData = _binarySerializer.Serialize(sendMessageResponse);

            return(new RemotingResponse((int)ResponseCode.Success, request.Sequence, responseData));
        }
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            var request        = _binarySerializer.Deserialize <SetQueueProducerVisibleForClusterRequest>(remotingRequest.Body);
            var requestService = new BrokerRequestService(_nameServerController);

            requestService.ExecuteActionToAllClusterBrokers(request.ClusterName, remotingClient =>
            {
                var requestData      = _binarySerializer.Serialize(new SetQueueProducerVisibleRequest(request.Topic, request.QueueId, request.Visible));
                var remotingResponse = remotingClient.InvokeSync(new RemotingRequest((int)BrokerRequestCode.SetQueueProducerVisible, requestData), 30000);
                if (remotingResponse.ResponseCode != ResponseCode.Success)
                {
                    throw new Exception(string.Format("SetQueueProducerVisible failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
                }
            });

            return(RemotingResponseFactory.CreateResponse(remotingRequest));
        }
        public RemotingResponse HandleRequest(IRequestHandlerContext context, RemotingRequest remotingRequest)
        {
            if (BrokerController.Instance.IsCleaning)
            {
                throw new BrokerCleanningException();
            }
            var request     = _binarySerializer.Deserialize <GetMessageDetailRequest>(remotingRequest.Body);
            var messageInfo = MessageIdUtil.ParseMessageId(request.MessageId);
            var message     = _messageStore.GetMessage(messageInfo.MessagePosition);
            var messages    = new List <QueueMessage>();

            if (message != null)
            {
                messages.Add(message);
            }
            return(RemotingResponseFactory.CreateResponse(remotingRequest, _binarySerializer.Serialize(messages)));
        }
Beispiel #28
0
        public Task <RemotingResponse> InvokeAsync(RemotingRequest request, int timeoutMillis)
        {
            EnsureClientStatus();

            request.Type = RemotingRequestType.Async;
            var taskCompletionSource = new TaskCompletionSource <RemotingResponse>();
            var responseFuture       = new ResponseFuture(request, timeoutMillis, taskCompletionSource);

            if (!_responseFutureDict.TryAdd(request.Sequence, responseFuture))
            {
                throw new ResponseFutureAddFailedException(request.Sequence);
            }

            _clientSocket.QueueMessage(RemotingUtils.BuildRequestMessage(request));

            return(taskCompletionSource.Task);
        }
Beispiel #29
0
        public async Task DeleteConsumerGroup(string clusterName, string brokerName, string consumerGroup)
        {
            var remotingClient = await GetBrokerByName(clusterName, brokerName);

            if (string.IsNullOrEmpty(consumerGroup))
            {
                throw new ArgumentException("consumerGroup cannot be null or empty.");
            }
            var requestData      = _binarySerializer.Serialize(new DeleteConsumerGroupRequest(consumerGroup));
            var remotingRequest  = new RemotingRequest((int)BrokerRequestCode.DeleteConsumerGroup, requestData);
            var remotingResponse = await remotingClient.InvokeAsync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode != ResponseCode.Success)
            {
                throw new Exception(string.Format("DeleteConsumerGroup failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
Beispiel #30
0
        public async Task SetQueueNextConsumeOffset(string clusterName, string brokerName, string consumerGroup, string topic, int queueId, long nextOffset)
        {
            var remotingClient = await GetBrokerByName(clusterName, brokerName);

            if (nextOffset < 0)
            {
                throw new ArgumentException("nextOffset cannot be small than zero.");
            }
            var requestData      = _binarySerializer.Serialize(new SetQueueNextConsumeOffsetRequest(consumerGroup, topic, queueId, nextOffset));
            var remotingRequest  = new RemotingRequest((int)BrokerRequestCode.SetQueueNextConsumeOffset, requestData);
            var remotingResponse = await remotingClient.InvokeAsync(remotingRequest, 30000);

            if (remotingResponse.ResponseCode != ResponseCode.Success)
            {
                throw new Exception(string.Format("SetQueueNextConsumeOffset failed, errorMessage: {0}", Encoding.UTF8.GetString(remotingResponse.ResponseBody)));
            }
        }
 public RemotingRequestToken(RemotingRequest request, DeferredObject deferred, Type returnType)
 {
     _request = request;
     _deferred = deferred;
     _returnType = returnType;
 }
Beispiel #32
0
        public object Invoke(object proxyObject, MethodInfo method, object[] arguments)
        {
            foreach (ParameterInfo parameter in method.GetParameters())
            {
                if (parameter.ParameterType.IsByRef)
                {
                    throw new InvalidOperationException("Remoting interfaces can not include methods that " +
                        "have \"out\" or \"ref\" parameters.");
                }
            }

            Type returnType = method.ReturnType;

            if (!Deferred.IsTypedDeferred(returnType))
            {
                throw new InvalidOperationException("Remoting interface methods must return a deferred.");
            }

            RemotingRequest request = new RemotingRequest(_protocol.GetNextCompletionCookieAndAdvance(),
                _stubId, _interfaceName, method.Name, arguments);

            DeferredObject deferred = Activator.CreateInstance(returnType) as DeferredObject;

            RemotingRequestToken token = new RemotingRequestToken(request, deferred, returnType);

            _protocol.SendRequest(token);

            return deferred;
        }
 public RemotingTimeoutException(string address, RemotingRequest request, int timeoutMillis)
     : base(string.Format("Wait response on the channel <{0}> timeout, request:{1}, timeoutMillis:{2}ms", address, request, timeoutMillis))
 {
 }
 public RemotingTimeoutException(EndPoint serverEndPoint, RemotingRequest request, long timeoutMillis)
     : base(string.Format("Wait response from server[{0}] timeout, request:{1}, timeoutMillis:{2}ms", serverEndPoint, request, timeoutMillis))
 {
 }
 public RemotingSendRequestException(string address, RemotingRequest request, Exception exception)
     : base(string.Format("Send request {0} to <{1}> failed.", request, address), exception)
 {
 }
 public RemotingRequestException(IPEndPoint serverEndPoint, RemotingRequest request, Exception exception)
     : base(string.Format("Send request {0} to server [{1}] failed.", request, serverEndPoint), exception)
 {
 }
 public RemotingRequestException(IPEndPoint serverEndPoint, RemotingRequest request, string errorMessage)
     : base(string.Format("Send request {0} to server [{1}] failed, errorMessage:{2}", request, serverEndPoint, errorMessage))
 {
 }