Пример #1
0
        public DefaultProducer(ProducerOptions options, IntPtr handle, IProducerNativeMethodsFacade producerFacade = null, DiagnosticListener diagnosticListener = null)
        {
            this.Options = options ?? throw new ArgumentNullException(nameof(options));

            if (handle == IntPtr.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(handle));
            }

            this.Handle              = new HandleRef(this, handle);
            this._producerFacade     = producerFacade ?? new ProducerNativeMethodsFacade();
            this._diagnosticListener = diagnosticListener;
        }
Пример #2
0
        public DefaultProducerBuilder(string groupName, IProducerNativeMethodsFacade producerFacade = null, DiagnosticListener diagnosticListener = null)
        {
            if (string.IsNullOrWhiteSpace(groupName))
            {
                throw new ArgumentNullException(nameof(groupName));
            }

            this._options = new ProducerOptions {
                GroupName = groupName
            };
            this._producerFacade     = producerFacade ?? new ProducerNativeMethodsFacade();
            this._diagnosticListener = diagnosticListener;

            var handle = this._producerFacade.CreateProducer(groupName);

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

            this._handleRef = new HandleRef(this, handle);
        }