public void Post([FromBody] RealtimeSubscription subscription)
 {
     // Set timestamps and save to database
     subscription.CreatedOn      = DateTimeOffset.Now;
     subscription.LastModifiedOn = subscription.CreatedOn;
     this.subscriptionService.Add(subscription);
 }
        /// <inheritdoc />
        public void Add(RealtimeSubscription subscription)
        {
            Guard.ArgumentNotNull(subscription, nameof(subscription));

            // Update fields
            var timestamp = DateTimeOffset.Now;

            subscription.IsActive       = true;
            subscription.CreatedOn      = timestamp;
            subscription.LastModifiedOn = timestamp;

            this.context.Subscriptions.Add(subscription);
            this.context.SaveChanges();
        }
        /// <summary>
        /// Forward message as specified in the given subscription.
        /// </summary>
        /// <param name="subscription">
        /// The subscription.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        private void ForwardMessage(RealtimeSubscription subscription, HL7Message message)
        {
            // Example routing key template: "HL7.{MessageType}.{EventType}"
            var exchangeName       = subscription.Name;
            var exchangeType       = "topic";
            var routingKey         = BuildRoutingKey(subscription, message);
            var serializedMessaged = JsonConvert.SerializeObject(message);
            var body = Encoding.UTF8.GetBytes(serializedMessaged);

            using (var connection = this.connectionFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchangeName, exchangeType);
                    channel.BasicPublish(exchangeName, routingKey, null, body);
                }
        }
예제 #4
0
        public void RealtimeSubscriptionServiceAddSubscription()
        {
            var expected = new RealtimeSubscription
            {
                Name = "A",
                SourceMessageType = "HL7",
                MessageFormat     = "RAW",
                RoutingKey        = "HL7.{MessageType}.{EventType}"
            };

            using (var ctx = CreateRealtimeContext())
            {
                var service = new RealtimeSubscriptionService(ctx);
                service.Add(expected);

                var actual = service.FindById(expected.Id);

                Assert.NotNull(actual);
                Assert.True(actual.Id > 0);
                Assert.Equal("HL7", actual.SourceMessageType);
                Assert.Equal("RAW", actual.MessageFormat);
                Assert.True(actual.IsActive);
            }
        }
 /// <summary>
 /// Builds the routing key.
 /// </summary>
 /// <param name="subscription">
 /// The subscription.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 private static string BuildRoutingKey(RealtimeSubscription subscription, HL7Message message)
 {
     return(subscription.RoutingKey.Replace("{MessageType}", message.MessageType.Trim())
            .Replace("{EventType}", message.EventType.Trim()));
 }
 public void Put([FromBody] RealtimeSubscription subscription)
 {
 }