コード例 #1
0
ファイル: Program.cs プロジェクト: zzyks/rocketmq-externals
        static void Main(string[] args)
        {
            Console.Title = "PushConsumer";

            Task.Run(() => {
                Console.WriteLine("start push consumer...");

                var consumerPtr = PushConsumerWrap.CreatePushConsumer("xxx");
                var p           = new Program();
                var consumer    = new HandleRef(p, consumerPtr);
                Console.WriteLine($"consumer: {consumer}");
                var r0 = PushConsumerWrap.SetPushConsumerLogLevel(consumer, CLogLevel.E_LOG_LEVEL_TRACE);

                var groupId = PushConsumerWrap.GetPushConsumerGroupID(consumer.Handle);
                Console.WriteLine($"groupId: {groupId}");

                var r1  = PushConsumerWrap.SetPushConsumerNameServerAddress(consumer, "47.101.55.250:9876");
                var r2  = PushConsumerWrap.Subscribe(consumer, "test", "*");
                var r3  = PushConsumerWrap.RegisterMessageCallback(consumer, _callback);
                var r10 = PushConsumerWrap.StartPushConsumer(consumer);
                Console.WriteLine($"start push consumer ptr: {r10}");

                while (true)
                {
                    Thread.Sleep(500);
                }
            });
            Console.ReadKey(true);

            //PushConsumerBinder.DestroyPushConsumer(consumer);
        }
コード例 #2
0
 public void Dispose()
 {
     if (this._handleRef.Handle != IntPtr.Zero)
     {
         PushConsumerWrap.DestroyPushConsumer(this._handleRef);
         this._handleRef = new HandleRef(null, IntPtr.Zero);
         GC.SuppressFinalize(this);
     }
 }
コード例 #3
0
        public IPushConsumerBuilder SetPushConsumerMessageModel(MessageModel messageModel)
        {
            var result = PushConsumerWrap.SetPushConsumerMessageModel(this._handleRef, (CMessageModel)messageModel);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer logFileNumAndSize error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #4
0
        public bool RegisterMessageCallback(PushConsumerWrap.MessageCallBack callBack)
        {
            if (callBack == null)
            {
                return(false);
            }

            var registerCallbackResult = PushConsumerWrap.RegisterMessageCallback(this._handleRef, callBack);

            return(registerCallbackResult == 0);
        }
コード例 #5
0
        public bool ShutdownPushConsumer()
        {
            if (this._handleRef.Handle == IntPtr.Zero)
            {
                return(false);
            }

            var shutdownResult = PushConsumerWrap.ShutdownPushConsumer(this._handleRef);

            return(shutdownResult == 0);
        }
コード例 #6
0
        public bool DestroyPushConsumer()
        {
            if (this._handleRef.Handle == IntPtr.Zero)
            {
                return(false);
            }

            var destroyResult = PushConsumerWrap.DestroyPushConsumer(this._handleRef);

            return(destroyResult == 0);
        }
コード例 #7
0
        public IPushConsumerBuilder SetPushConsumerLogLevel(LogLevel logLevel)
        {
            if (logLevel == LogLevel.None)
            {
                throw new ArgumentException(nameof(logLevel));
            }

            var result = PushConsumerWrap.SetPushConsumerLogLevel(this._handleRef, (CLogLevel)logLevel);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer logLevel error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #8
0
        public IPushConsumerBuilder SetPushConsumerLogPath(string logPath)
        {
            if (string.IsNullOrWhiteSpace(logPath))
            {
                throw new ArgumentNullException(nameof(logPath));
            }

            var result = PushConsumerWrap.SetPushConsumerLogPath(this._handleRef, logPath);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer logPath error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #9
0
        public IPushConsumerBuilder SetPushConsumerInstanceName(string instanceName)
        {
            if (string.IsNullOrWhiteSpace(instanceName))
            {
                throw new ArgumentNullException(nameof(instanceName));
            }

            var result = PushConsumerWrap.SetPushConsumerInstanceName(this._handleRef, instanceName);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer instanceName error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #10
0
        public IPushConsumerBuilder SetPushConsumerGroupId(string groupId)
        {
            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentNullException(nameof(groupId));
            }

            var result = PushConsumerWrap.SetPushConsumerGroupID(this._handleRef, groupId);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer groupId error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #11
0
        public IPushConsumerBuilder SetPushConsumerThreadCount(int threadCount)
        {
            if (threadCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(threadCount));
            }

            var result = PushConsumerWrap.SetPushConsumerThreadCount(this._handleRef, threadCount);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer threadCount error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #12
0
        public void SetPushConsumerNameServerAddress(string nameServerAddress)
        {
            if (string.IsNullOrWhiteSpace(nameServerAddress))
            {
                throw new ArgumentNullException(nameof(nameServerAddress));
            }

            var result = PushConsumerWrap.SetPushConsumerNameServerAddress(this._handleRef, nameServerAddress);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer nameServerAddress error. cpp sdk return code {result}");
            }

            return;
        }
コード例 #13
0
        public IPushConsumerBuilder SetPushConsumerNameServerDomain(string domain)
        {
            if (string.IsNullOrWhiteSpace(domain))
            {
                throw new ArgumentNullException(nameof(domain));
            }

            var result = PushConsumerWrap.SetPushConsumerNameServerDomain(this._handleRef, domain);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer domain error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #14
0
        public IPushConsumerBuilder SetPushConsumerMessageBatchMaxSize(int batchSize)
        {
            if (batchSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(batchSize));
            }

            var result = PushConsumerWrap.SetPushConsumerMessageBatchMaxSize(this._handleRef, batchSize);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer batchSize error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #15
0
        public DefaultPushConsumerBuilder(string groupId)
        {
            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentNullException(nameof(groupId));
            }

            var handle = PushConsumerWrap.CreatePushConsumer(groupId);

            if (handle == IntPtr.Zero)
            {
                throw new RocketMQConsumerException($"create consumer error, ptr is {handle}");
            }

            this._handleRef = new HandleRef(this, handle);
        }
コード例 #16
0
        private void MQPushConsumerInit(string groupId)
        {
            if (string.IsNullOrWhiteSpace(groupId))
            {
                throw new ArgumentNullException(nameof(groupId));
            }

            var handle = PushConsumerWrap.CreatePushConsumer(groupId);

            if (handle == IntPtr.Zero)
            {
                throw new RocketMQConsumerException($"create consumer error, ptr is {handle}");
            }

            this._handleRef = new HandleRef(this, handle);
            this.SetPushConsumerLogPath(this.LogPath);
        }
コード例 #17
0
        public void Subscribe(string topic, string expression)
        {
            if (string.IsNullOrWhiteSpace(topic))
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (string.IsNullOrWhiteSpace(expression))
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var result = PushConsumerWrap.Subscribe(this._handleRef, topic, expression);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"push consumer subscribe error. cpp sdk return code: {result}");
            }
        }
コード例 #18
0
        public IPushConsumerBuilder SetPushConsumerLogFileNumAndSize(int fileNum, long fileSize)
        {
            if (fileNum <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(fileNum));
            }
            if (fileSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(fileSize));
            }

            var result = PushConsumerWrap.SetPushConsumerLogFileNumAndSize(this._handleRef, fileNum, fileSize);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer logFileNumAndSize error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #19
0
        public IPushConsumerBuilder SetPushConsumerSessionCredentials(string accessKey, string secretKey, string channel)
        {
            if (string.IsNullOrWhiteSpace(accessKey))
            {
                throw new ArgumentNullException(nameof(accessKey));
            }
            if (string.IsNullOrWhiteSpace(secretKey))
            {
                throw new ArgumentNullException(nameof(secretKey));
            }
            if (string.IsNullOrWhiteSpace(channel))
            {
                throw new ArgumentNullException(nameof(channel));
            }

            var result = PushConsumerWrap.SetPushConsumerSessionCredentials(this._handleRef, accessKey, secretKey, channel);

            if (result != 0)
            {
                throw new RocketMQConsumerException($"set consumer sessionCredentials error. cpp sdk return code {result}");
            }

            return(this);
        }
コード例 #20
0
        public bool StartPushConsumer()
        {
            var startResult = PushConsumerWrap.StartPushConsumer(this._handleRef);

            return(startResult == 0);
        }
コード例 #21
0
 public string GetPushConsumerGroupID()
 {
     return(PushConsumerWrap.GetPushConsumerGroupID(this._handleRef.Handle));
 }