예제 #1
0
        public async Task SendMessage(StoreEvent storeEvent)
        {
            if (!_active)
            {
                // pass through
                _queueContainer.Send(storeEvent);
                return;
            }

            try {
                int ehPartitionId;
                if (!string.IsNullOrEmpty(storeEvent.PartitionId))
                {
                    ehPartitionId = storeEvent.PartitionId.GetHashCode() % _storeConfig.EventHubPartitionCount;
                }
                else
                {
                    ehPartitionId = storeEvent.StoreId.GetHashCode() % _storeConfig.EventHubPartitionCount;
                }
                var content = JsonConvert.SerializeObject(storeEvent, Formatting.None);
                var bytes   = Encoding.UTF8.GetBytes(content);
                await _eventHubClient.SendAsync(new EventData(bytes), ehPartitionId.ToString());
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }