예제 #1
0
        private async Task AddNewTopic()
        {
            var newTopic = new Models.ForumTopic
            {
                Title              = _forumTopic.Title,
                ForumTopicUrl      = _forumTopic.ForumTopicUrl,
                TopicText          = _forumTopic.TopicText,
                UserId             = CurrentUserId,
                PostedDate         = DateTime.Now.ToUniversalTime(),
                ForumCategoryId    = ForumCatId,
                Flags              = 0,
                IsModeratorChanged = false,
                IsDeleted          = false,
                IsApproved         = true,
                //UserIP = httpContext.HttpContext.Connection.RemoteIpAddress.ToString() // Was failing on server - fine locally
            };
            var postedId = await manageForumTopics.PostNewTopicAsync(newTopic);

            if (postedId != 0)
            {
                var newTopicSubscription = new TopicSubscription {
                    ForumTopicId = postedId, Id = CurrentUserId
                };
                var subscriptionAdded = await manageTopicSubscriptions.AddSubscriptionToTopicAsync(newTopicSubscription);
            }
        }
        public void Start()
        {
            _subscriber = new NetMqSubscriber(_pubsubServerAddress,
                                              new DefaultConnectionMonitor(OnConnectionStateChanged));

            var quotesTopic = new TopicSubscription <Quote>
            {
                Topic          = "q",
                Deserializer   = BinarySerializer <Quote> .DeSerializeFromByteArray,
                MessageHandler = _quoteReceivedAction
            };

            _synchronizers.Add(new TopicSynchronizer <ushort, Quote, IEnumerable <Quote> >(_subscriber,
                                                                                           quotesTopic,
                                                                                           _quotesCache,
                                                                                           CreateSnapshotClient,
                                                                                           (q1, q2) => q2.LastUpdate > q1.LastUpdate,
                                                                                           q => true, q => q.InstrumentId, x => x));

            if (!_subscriber.StartProducer(60000))
            {
                Debug.WriteLine("Starting Producer FAILED- connecting subscriber - TIMEDOUT");
                return;
            }

            _subscriber.StartConsumer();
        }
        public void Start()
        {
            _subscriber = new NetMqSubscriber(_pubsubServerAddress,
                new DefaultConnectionMonitor(OnConnectionStateChanged));

            var quotesTopic = new TopicSubscription<Quote>
            {
                Topic = Constants.QuotesTopicName,
                Deserializer = BinarySerializer<Quote>.DeSerializeFromByteArray,
                MessageHandler = _quoteReceivedAction
            };

            _synchronizers.Add(new TopicSynchronizer<string, Quote, IEnumerable<Quote>>(_subscriber,
                quotesTopic,
                _quotesCache,
                CreateSnapshotClient,
                (q1, q2) => q2.ProcessedTime > q1.ProcessedTime,
                q => true, q => q.Instrument, x => x));

            if (!_subscriber.StartProducer(60000))
            {
                Debug.WriteLine("Starting Producer FAILED- connecting subscriber - TIMEDOUT");
                return;
            }

            _subscriber.StartConsumer();
        }
예제 #4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Topic.Length != 0)
            {
                hash ^= Topic.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Client)
            {
                hash ^= Client.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Device)
            {
                hash ^= Device.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicSubscription)
            {
                hash ^= TopicSubscription.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Session)
            {
                hash ^= Session.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.SessionList)
            {
                hash ^= SessionList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Interaction)
            {
                hash ^= Interaction.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.InteractionList)
            {
                hash ^= InteractionList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMux)
            {
                hash ^= TopicMux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMuxList)
            {
                hash ^= TopicMuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemux)
            {
                hash ^= TopicDemux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemuxList)
            {
                hash ^= TopicDemuxList.GetHashCode();
            }
            hash ^= (int)typeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
예제 #5
0
 public ITopicSubscription CreateTopicSubscription()
 {
     lock (_Topics) {
         var sub = new TopicSubscription(this);
         _Topics.Add(sub);
         return(sub);
     }
 }
        public void Test_Snapshot_Behind_Stream_EmptyCache()
        {
            var cache          = new DefaultLastValueCache <int, MockMessage>();
            var subscriber     = new MockTopicSubscriber();
            var snapshotClient = new MockSnapshotClient
            {
                Data = new[]
                {
                    new MockMessage {
                        Data = new byte[] { 1, 11 }
                    },
                    new MockMessage {
                        Data = new byte[] { 2, 22 }
                    },
                    new MockMessage {
                        Data = new byte[] { 3, 33 }
                    }
                }
            };

            var subscription = new TopicSubscription <MockMessage>
            {
                Topic        = "",
                Deserializer = m => new MockMessage {
                    Data = m
                },
                MessageHandler = m => Debug.WriteLine("[{0},{1}]", m.Data[0], m.Data[1])
            };

            var synchronizer = new TopicSynchronizer <int, MockMessage, IList <MockMessage> >(
                subscriber, subscription, cache,
                s => snapshotClient,
                (newValue, cachedValue) => newValue.Data[1] > cachedValue.Data[1],
                m => m.Data[1] >= 10,
                m => m.Data[0],
                x => x);


            Assert.IsTrue(cache.IsEmpty);

            Task.Run(() =>
            {
                for (byte i = 50; i < 250; i++)
                {
                    subscriber.InvokeSubscriptionAccessor("", new byte[] { 1, i });
                    Thread.Sleep(10);
                }
            });

            synchronizer.Init();
            Assert.AreEqual(3, cache.Count);
            subscriber.InvokeSubscriptionAccessor("", new byte[] { 1, 10 });
            Assert.AreEqual(3, cache.Count);
            Assert.IsTrue(cache[1].Data[1] >= 50);
            subscriber.InvokeSubscriptionAccessor("", new byte[] { 1, 9 });
            Assert.IsTrue(cache[1].Data[1] >= 50);
        }
        Task Declare(ModelContext context, TopicSubscription subscription)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Binding topic ({0}) to queue ({1})", subscription.Source, subscription.Destination);
            }

            return(context.GetTopicSubscription(subscription.Source.EntityName, subscription.Destination.EntityName));
        }
        Task Create(NamespaceContext context, TopicSubscription subscription)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Create Topic Subscription ({0})", subscription);
            }

            return(context.CreateTopicSubscription(subscription.Subscription.SubscriptionDescription));
        }
        public static TopicSubscriptionSettings GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = new TopicDescription(messageNameFormatter.GetMessageName(messageType).ToString());

            var binding = new TopicSubscription(topicDescription);

            return binding;
        }
예제 #10
0
        private async Task SubscribeUserToTopic()
        {
            var newSubscription = new TopicSubscription {
                Id           = CurrentUserId,
                ForumTopicId = id
            };
            await manageTopicSubscriptions.AddSubscriptionToTopicAsync(newSubscription);

            await CheckIfUserIsSubscribed();
        }
예제 #11
0
        public static TopicSubscriptionSettings GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = new TopicDescription(messageNameFormatter.GetMessageName(messageType).ToString());

            var binding = new TopicSubscription(topicDescription);

            return(binding);
        }
예제 #12
0
    static void Main()
    {
        // bootstrap the external task client
        ExternalTaskClient client = ExternalTaskClient.create()
                                    .endpoint("http://localhost:8080/engine-rest")
                                    .build();

        // subscribe to a topic name
        TopicSubscription topic = client.subscribe("invoiceCreator")
                                  .handler(new MyHandler())
                                  .open();
    }
        public static IEnumerable<TopicSubscriptionSettings> GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            if (!IsSubscriptionMessageType(messageType))
                yield break;

            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = Defaults.CreateTopicDescription(messageNameFormatter.GetMessageName(messageType).ToString());
            topicDescription.EnableExpress = temporary;

            var binding = new TopicSubscription(topicDescription);

            yield return binding;
        }
        public static TopicSubscriptionSettings GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = new TopicDescription(messageNameFormatter.GetMessageName(messageType).ToString())
            {
                EnableBatchedOperations  = true,
                EnableExpress            = temporary,
                DefaultMessageTimeToLive = TimeSpan.FromDays(365)
            };

            var binding = new TopicSubscription(topicDescription);

            return(binding);
        }
예제 #15
0
        public async Task AddSubscriptionAndSendEmailToSubscribers(int topicId, string currentUserId, string topicSlug)
        {
            try
            {
                var newTopicSubscription = new TopicSubscription {
                    ForumTopicId = topicId, Id = currentUserId
                };
                var subscriptionAdded = await _manageTopicSubscriptions.AddSubscriptionToTopicAsync(newTopicSubscription);

                string url = _httpContextAccessor.HttpContext.Request.Scheme + "://" + _httpContextAccessor.HttpContext.Request.Host + "/topic/" + topicId + "/" + topicSlug;
                await new Utilities.ForumNotifications.EmailNotifications(_manageForumTopics, _userManager, _emailSender, _manageTopicSubscriptions)
                .SendTopicReplyEmailNotification(topicId, currentUserId, url);
            }
            catch (Exception ex)
            {
            }
        }
        public static IEnumerable <TopicSubscriptionSettings> GetTopicSubscription(this IMessageNameFormatter messageNameFormatter, Type messageType)
        {
            if (!IsSubscriptionMessageType(messageType))
            {
                yield break;
            }

            bool temporary = IsTemporaryMessageType(messageType);

            var topicDescription = Defaults.CreateTopicDescription(messageNameFormatter.GetMessageName(messageType).ToString());

            topicDescription.EnableExpress = temporary;

            var binding = new TopicSubscription(topicDescription);

            yield return(binding);
        }
예제 #17
0
        public async Task <bool> AddSubscriptionToTopicAsync(TopicSubscription newSubscription)
        {
            var subscriptions = _context.TopicSubscriptions;

            // Make sure the user isn't already subscribed
            var currentSubscription = await subscriptions
                                      .Where(p => p.ForumTopicId == newSubscription.ForumTopicId && p.Id == newSubscription.Id)
                                      .FirstOrDefaultAsync();

            if (currentSubscription == null)
            {
                await subscriptions.AddAsync(newSubscription);

                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
예제 #18
0
        public async Task <bool> SubscribeUserToTopicAsync(TopicSubscription newSubscription)
        {
            using var context = _dbFactory.CreateDbContext();
            var subscriptions = context.TopicSubscriptions;

            // Make sure the user isn't already subscribed
            var currentSubscription = await subscriptions
                                      .Where(p => p.ForumTopicId == newSubscription.ForumTopicId && p.Id == newSubscription.Id)
                                      .FirstOrDefaultAsync();

            if (currentSubscription == null)
            {
                await subscriptions.AddAsync(newSubscription);

                await context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }
예제 #19
0
        public async Task <bool> AddSubscriptionAndSendEmailToSubscribersAsync(int topicId, string currentUserId, string topicSlug)
        {
            try
            {
                var newTopicSubscription = new TopicSubscription {
                    ForumTopicId = topicId, Id = currentUserId
                };
                var subscriptionAdded = await _manageTopicSubscriptions.SubscribeUserToTopicAsync(newTopicSubscription);

                string url = _httpContextAccessor.HttpContext.Request.Scheme + "://" + _httpContextAccessor.HttpContext.Request.Host + "/topic/" + topicId + "/" + topicSlug;
                await _emailNotificationsService.SendTopicReplyEmailNotificationAsync(topicId, currentUserId, url);

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex.Message);

                return(false);
            }
        }
예제 #20
0
        // FYI Here where ServiceB tells Dapr which Pubsub subscriptions it can handle.
        public override Task <ListTopicSubscriptionsResponse> ListTopicSubscriptions(Empty request, ServerCallContext context)
        {
            var result = new ListTopicSubscriptionsResponse();

            try
            {
                TopicSubscription subscr;

                subscr = new TopicSubscription
                {
                    PubsubName = NamesOfQueuesNPubSubs.PubSubAzServiceBusComponent,
                    Topic      = NamesOfQueuesNPubSubs.ServiceADemoEvent1Topic
                };
                result.Subscriptions.Add(subscr);
                // For display in a running demo.
                Console.WriteLine($" ** ServiceB: Subscribed to Topic={subscr.Topic} for PubsubName={subscr.PubsubName}");


                // For Dapr default Redis pubsub component.  Also needs event processing code in OnTopicEvent() below.
                subscr = new TopicSubscription()
                {
                    PubsubName = NamesOfQueuesNPubSubs.PubSubDefaultDaprComponent,
                    Topic      = NamesOfQueuesNPubSubs.ServiceADemoEvent1Topic
                };
                result.Subscriptions.Add(subscr);
                // For display in a running demo.
                Console.WriteLine($" ** ServiceB: Subscribed to Topic={subscr.Topic} for PubsubName={subscr.PubsubName}");
            }
            catch (Exception ex)
            {
                m_Logger.LogError($"** ServiceB.ListTopicSubscriptions() threw exception ex={ex}");
                throw;
            }

            // TODO If required, add subscription for NamesOfQueuesNPubSubs.ServiceADemoEvents2Topic

            return(Task.FromResult(result));
        }
예제 #21
0
        public void MergeFrom(ServiceRequest other)
        {
            if (other == null)
            {
                return;
            }
            if (other.Topic.Length != 0)
            {
                Topic = other.Topic;
            }
            switch (other.TypeCase)
            {
            case TypeOneofCase.Client:
                if (Client == null)
                {
                    Client = new global::Ubii.Clients.Client();
                }
                Client.MergeFrom(other.Client);
                break;

            case TypeOneofCase.Device:
                if (Device == null)
                {
                    Device = new global::Ubii.Devices.Device();
                }
                Device.MergeFrom(other.Device);
                break;

            case TypeOneofCase.TopicSubscription:
                if (TopicSubscription == null)
                {
                    TopicSubscription = new global::Ubii.Services.Request.TopicSubscription();
                }
                TopicSubscription.MergeFrom(other.TopicSubscription);
                break;

            case TypeOneofCase.Session:
                if (Session == null)
                {
                    Session = new global::Ubii.Sessions.Session();
                }
                Session.MergeFrom(other.Session);
                break;

            case TypeOneofCase.SessionList:
                if (SessionList == null)
                {
                    SessionList = new global::Ubii.Sessions.SessionList();
                }
                SessionList.MergeFrom(other.SessionList);
                break;

            case TypeOneofCase.ProcessingModule:
                if (ProcessingModule == null)
                {
                    ProcessingModule = new global::Ubii.Processing.ProcessingModule();
                }
                ProcessingModule.MergeFrom(other.ProcessingModule);
                break;

            case TypeOneofCase.ProcessingModuleList:
                if (ProcessingModuleList == null)
                {
                    ProcessingModuleList = new global::Ubii.Processing.ProcessingModuleList();
                }
                ProcessingModuleList.MergeFrom(other.ProcessingModuleList);
                break;

            case TypeOneofCase.TopicMux:
                if (TopicMux == null)
                {
                    TopicMux = new global::Ubii.Devices.TopicMux();
                }
                TopicMux.MergeFrom(other.TopicMux);
                break;

            case TypeOneofCase.TopicMuxList:
                if (TopicMuxList == null)
                {
                    TopicMuxList = new global::Ubii.Devices.TopicMuxList();
                }
                TopicMuxList.MergeFrom(other.TopicMuxList);
                break;

            case TypeOneofCase.TopicDemux:
                if (TopicDemux == null)
                {
                    TopicDemux = new global::Ubii.Devices.TopicDemux();
                }
                TopicDemux.MergeFrom(other.TopicDemux);
                break;

            case TypeOneofCase.TopicDemuxList:
                if (TopicDemuxList == null)
                {
                    TopicDemuxList = new global::Ubii.Devices.TopicDemuxList();
                }
                TopicDemuxList.MergeFrom(other.TopicDemuxList);
                break;

            case TypeOneofCase.ClientList:
                if (ClientList == null)
                {
                    ClientList = new global::Ubii.Clients.ClientList();
                }
                ClientList.MergeFrom(other.ClientList);
                break;

            case TypeOneofCase.DeviceList:
                if (DeviceList == null)
                {
                    DeviceList = new global::Ubii.Devices.DeviceList();
                }
                DeviceList.MergeFrom(other.DeviceList);
                break;

            case TypeOneofCase.LockstepProcessingRequest:
                if (LockstepProcessingRequest == null)
                {
                    LockstepProcessingRequest = new global::Ubii.Processing.LockstepProcessingRequest();
                }
                LockstepProcessingRequest.MergeFrom(other.LockstepProcessingRequest);
                break;
            }

            _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
        }
예제 #22
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Topic.Length != 0)
            {
                hash ^= Topic.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Client)
            {
                hash ^= Client.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Device)
            {
                hash ^= Device.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicSubscription)
            {
                hash ^= TopicSubscription.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.Session)
            {
                hash ^= Session.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.SessionList)
            {
                hash ^= SessionList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ProcessingModule)
            {
                hash ^= ProcessingModule.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ProcessingModuleList)
            {
                hash ^= ProcessingModuleList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMux)
            {
                hash ^= TopicMux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicMuxList)
            {
                hash ^= TopicMuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemux)
            {
                hash ^= TopicDemux.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.TopicDemuxList)
            {
                hash ^= TopicDemuxList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.ClientList)
            {
                hash ^= ClientList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.DeviceList)
            {
                hash ^= DeviceList.GetHashCode();
            }
            if (typeCase_ == TypeOneofCase.LockstepProcessingRequest)
            {
                hash ^= LockstepProcessingRequest.GetHashCode();
            }
            hash ^= (int)typeCase_;
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
 Task Create(NamespaceContext context, TopicSubscription subscription)
 {
     return(context.CreateTopicSubscription(subscription.Subscription.SubscriptionDescription, subscription.Subscription.Rule,
                                            subscription.Subscription.Filter));
 }
 protected bool Equals(TopicSubscription other)
 {
     return Topic.Path.Equals(other.Topic.Path);
 }
예제 #25
0
 protected bool Equals(TopicSubscription other)
 {
     return(Topic.Path.Equals(other.Topic.Path));
 }
예제 #26
0
파일: Program.cs 프로젝트: valcinei/lab
    static Task <int> Main()
    {
        var config = new ConfigurationBuilder()
                     .AddUserSecrets(typeof(Program).Assembly)
                     .Build();

        var accountId = config.GetValue <string>("AccountId");
        var role      = config.GetValue <string>("Role");

        return(Deployment.RunAsync(() =>
        {
            var roleArn = Output.Format($"arn:aws:iam::{accountId}:role/{role}");

            var providerArgs = new ProviderArgs
            {
                Region = "eu-west-1",
                AssumeRole = new ProviderAssumeRoleArgs
                {
                    RoleArn = roleArn,
                    SessionName = "session"
                }
            };

            var provider = new Provider("sandboxEUWest1Provider", providerArgs);

            var options = new CustomResourceOptions
            {
                Provider = provider
            };

            // Worker SNS Notification
            var notificationTopicArgs = new TopicArgs
            {
                Name = "WorkerNotification",
            };
            var workerNotificationTopic = new Topic("workerNotification", notificationTopicArgs, options);

            // Lambda
            var functionType = typeof(Worker.Function);
            var handler = $"{functionType.Assembly.GetName().Name}::{functionType.FullName}::FunctionHandler";

            var function = new Function("WorkerFunction", new FunctionArgs
            {
                Name = "WorkerFunction",
                Runtime = "dotnetcore3.1",
                Environment = new FunctionEnvironmentArgs
                {
                    Variables = new InputMap <string>
                    {
                        { $"{Worker.Function.NotificationTopicArnKey}", workerNotificationTopic.Arn }
                    }
                },
                Code = new FileArchive("../Worker/bin/Release/netcoreapp3.1/publish"),
                ReservedConcurrentExecutions = 1,
                Handler = handler,
                Role = CreateLambdaRole(options).Arn,
                MemorySize = 512,
                Timeout = 60
            }, options);

            var permission = new Permission("WorkerSNSPermission", new PermissionArgs
            {
                Action = "lambda:InvokeFunction",
                Function = function.Arn,
                Principal = "sns.amazonaws.com",
                SourceArn = workerNotificationTopic.Arn,
            }, options);

            // Subscription
            var workerSubscription = new TopicSubscription("workerNotificationSubscription", new TopicSubscriptionArgs
            {
                Topic = workerNotificationTopic.Arn,
                Protocol = "lambda",
                Endpoint = function.Arn
            }, options);
        }));
    }
예제 #27
0
 public async Task <bool> AddSubscriptionToTopicAsync(TopicSubscription newSubscription) =>
 await new Data.Repository.TopicSubscriptions(_dbFactory).AddSubscriptionToTopicAsync(newSubscription);