Exemple #1
0
 public TsdbClient(
     IStorageSelector <TKey, TEntry> storageSelector,
     IPublishSubscribe <TKey, TEntry> remotePublishSubscribe,
     ITsdbLogger logger)
     : this(storageSelector, remotePublishSubscribe, null, logger)
 {
 }
Exemple #2
0
 public TsdbClient(
     IStorageSelector <TKey, TEntry> storageSelector,
     IPublishSubscribe <TKey, TEntry> remotePublishSubscribe,
     ITemporaryStorage <TKey, TEntry> temporaryStorage)
     : this(storageSelector, remotePublishSubscribe, temporaryStorage, NullTsdbLogger.Default)
 {
 }
Exemple #3
0
 public TsdbClient(
     IDynamicStorageSelector <TKey, TEntry> dynamicStorageSelector,
     IVolumeStorageSelector <TKey, TEntry> volumeStorageSelector,
     IPublishSubscribe <TKey, TEntry> remotePublishSubscribe,
     ITemporaryStorage <TKey, TEntry> temporaryStorage)
     : this(dynamicStorageSelector, volumeStorageSelector, remotePublishSubscribe, temporaryStorage, NullTsdbLogger.Default)
 {
 }
Exemple #4
0
 public TsdbClient(
     IDynamicStorageSelector <TKey, TEntry> dynamicStorageSelector,
     IVolumeStorageSelector <TKey, TEntry> volumeStorageSelector,
     IPublishSubscribe <TKey, TEntry> remotePublishSubscribe,
     ITsdbLogger logger)
     : this(dynamicStorageSelector, volumeStorageSelector, remotePublishSubscribe, null, logger)
 {
 }
 public PublishSubscribeQueueAdapterReceiver(QueueId queueId,
                                             IPublishSubscribe publishSubscribe,
                                             SerializationManager serializationManager)
 {
     _publishSubscribe     = publishSubscribe;
     _serializationManager = serializationManager;
     _queueId = queueId;
 }
Exemple #6
0
 public TsdbClient(
     IStorageSelector <TKey, TEntry> storageSelector,
     IPublishSubscribe <TKey, TEntry> remotePublishSubscribe,
     ITemporaryStorage <TKey, TEntry> temporaryStorage,
     ITsdbLogger logger)
 {
     _storageSelector        = storageSelector;
     _remotePublishSubscribe = remotePublishSubscribe;
     _temporaryStorage       = temporaryStorage;
     _localPublishSubscribe  = new DefaultPublishSubscribe <TKey, TEntry>(false);
     _logger = logger;
 }
 public PubSubForwarderWampRawTopicRouterSubscriber(
     string publisherId,
     string forwarderPubSubTopic,
     IWampTopic wampTopic,
     IPublishSubscribe publishSubscribe,
     AtomicBoolean disableInternalPublishAtomicBoolean)
 {
     _publisherId      = publisherId;
     _wampTopic        = wampTopic;
     _publishSubscribe = publishSubscribe;
     _disableInternalPublishAtomicBoolean = disableInternalPublishAtomicBoolean;
     _forwarderPubSubTopic = forwarderPubSubTopic;
 }
        public void Init(IProviderConfiguration config, string providerName, IServiceProvider serviceProvider)
        {
            Name = providerName;

            _publishSubscribe     = serviceProvider.GetRequiredService <IPublishSubscribe>();
            _serializationManager = serviceProvider.GetRequiredService <SerializationManager>();
            ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();

            PublishSubscribeStreamConfiguration publishSubscribeStreamConfiguration = new PublishSubscribeStreamConfiguration(config);

            _adapterCache      = new SimpleQueueAdapterCache(publishSubscribeStreamConfiguration.InMemoryCacheSize, providerName, loggerFactory);
            _streamQueueMapper = new HashRingBasedStreamQueueMapper(publishSubscribeStreamConfiguration.NumberOfQueues, providerName);
        }
Exemple #9
0
        public PublishSubscribeDistributedCache(string cacheGroup,
                                                IPublishSubscribe publishSubscribe)
        {
            _publishSubscribe = publishSubscribe ?? throw new ArgumentNullException(nameof(publishSubscribe));

            MemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions
            {
                CompactionPercentage = 0.1
            });

            _getTopic    = cacheGroup + "_get";
            _setTopic    = cacheGroup + "_set";
            _removeTopic = cacheGroup + "_remove";

            publishSubscribe
            .Observe <byte[]>(_setTopic)
            .Subscribe(_ =>
            {
                CacheEntry cacheEntry = CacheEntry.Parser.ParseFrom(_.Data);
                memoryCache.Set(cacheEntry.Key, cacheEntry);
            }, CancellationToken);

            publishSubscribe
            .Observe <string>(_removeTopic)
            .Subscribe(_ => { memoryCache.Remove(_.Data); }, CancellationToken);

            publishSubscribe
            .Observe <byte[]>(_getTopic)
            .Subscribe(_ =>
            {
                CacheRequest cacheRequest = CacheRequest.Parser.ParseFrom(_.Data);
                CacheEntry value          = memoryCache.Get <CacheEntry>(cacheRequest.Key) ?? new CacheEntry
                {
                    Key = cacheRequest.Key
                };
                publishSubscribe.Publish(cacheRequest.TopicResponse, value.ToByteArray());
            }, CancellationToken);

            _selfTopic = Guid.NewGuid().ToString();
            publishSubscribe
            .Observe <byte[]>(_selfTopic)
            .Subscribe(_ =>
            {
                CacheEntry cacheEntry = CacheEntry.Parser.ParseFrom(_.Data);
                if (_completionSources.TryRemove(cacheEntry.Key, out TaskCompletionSource <byte[]> taskCompletionSource))
                {
                    taskCompletionSource.TrySetResult(cacheEntry.Value.ToByteArray());
                }
            }, CancellationToken);
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Blog post service.");
            Console.ReadLine();
            Entry();

            IPublishSubscribe    bus  = BasicContainer.IOC.Resolve <IPublishSubscribe>();
            BlogPostMicroservice blog = BasicContainer.IOC.Resolve <BlogPostMicroservice>();

            bus.Connect();
            //blog.AddBlogPost(0, "First post");

            Console.ReadLine();
        }
        public void Initialize()
        {
            if (!BasicContainer.IOC.IsTypeRegistered <IPublishSubscribe>())
            {
                throw new ArgumentNullException("No bus transport registered.");
            }

            if (!BasicContainer.IOC.IsTypeRegistered <IRepository <E, EId> >())
            {
                throw new ArgumentNullException($"No repository of type {typeof(E).Name} with Id {typeof(EId).Name} registered.");
            }

            _bus       = BasicContainer.IOC.Resolve <IPublishSubscribe>();
            Repository = BasicContainer.IOC.Resolve <IRepository <E, EId> >();
        }
Exemple #12
0
 public TsdbClient(
     IDynamicStorageSelector <TKey, TEntry> dynamicStorageSelector,
     IVolumeStorageSelector <TKey, TEntry> volumeStorageSelector,
     IPublishSubscribe <TKey, TEntry> remotePublishSubscribe,
     ITemporaryStorage <TKey, TEntry> temporaryStorage,
     ITsdbLogger logger)
 {
     _dynamicStorageSelector = dynamicStorageSelector;
     _volumeStorageSelector  = volumeStorageSelector;
     _remotePublishSubscribe = remotePublishSubscribe;
     _temporaryStorage       = temporaryStorage;
     _localPublishSubscribe  = new DefaultPublishSubscribe <TKey, TEntry>(false);
     _logger     = logger;
     _migrations = new MigrationProvider <TKey, TEntry>(_dynamicStorageSelector, _volumeStorageSelector);
 }
Exemple #13
0
        public OrleansStartup(string clusterName)
        {
            ILoggerFactory       loggerFactory = new NullLoggerFactory();
            ISerializer <byte[]> serializer    = new MessagePackSerializer();

            PublishSubscribe = new PublishSubscribeBuilder(new WireSerializer())
                               .SetLoggerFactory(loggerFactory)
                               .SetSerializer(serializer)
                               .ProtoActorPublishSubscribe()
                               .Build();

            // Start ProtoActor Cluster
            int serverPort = PortUtils.FindAvailablePortIncrementally(41000);

            Cluster.Start("unique", "127.0.0.1", serverPort,
                          new SeededLocalClusterProvider(Observable.Return(new[] { new IPEndPoint(IPAddress.Loopback, 41000) })));
        }
Exemple #14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Blog Service.");
            Console.ReadLine();

            Entry();

            IPublishSubscribe bus = BasicContainer.IOC.Resolve <IPublishSubscribe>();

            BlogMicroservice blog     = BasicContainer.IOC.Resolve <BlogMicroservice>();
            BlogPostHandlers handlers = BasicContainer.IOC.Resolve <BlogPostHandlers>();

            bus.RegisterHandler <BlogPostAdded>(handlers.BlogPostAdded);
            bus.RegisterHandler <BlogAdded>(handlers.BlogAdded);

            bus.Connect();
            Console.WriteLine("Connected.");

            Console.ReadLine();
            blog.AddBlog("New Blog", "Blog's description.");
            Console.WriteLine("Sent data.");

            Console.ReadLine();
            blog.AddBlog("New Blog", "Blog's description.");
            Console.WriteLine("Sent data.");

            Console.ReadLine();
            blog.AddBlog("New Blog", "Blog's description.");
            Console.WriteLine("Sent data.");

            Console.ReadLine();
            blog.AddBlog("New Blog", "Blog's description.");
            Console.WriteLine("Sent data.");

            Console.ReadLine();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            IPublishSubscribe bus = BasicContainer.IOC.Resolve <IPublishSubscribe>();

            ProjectionOrSomething projection  = new ProjectionOrSomething();
            UserService           userService = new UserService();

            //bus.RegisterHandler<EventSending>(projection.Handle);
            //bus.RegisterHandler<Event2>(projection.Handle);
            //
            //bus.RegisterHandler<RegisterUser>(userService.Handle);

            bus.Connect();

            Console.WriteLine("How many ms per message: ");
            int delay = int.Parse(Console.ReadLine());

            Console.WriteLine("How many kilobytes per message: ");
            int kbs = int.Parse(Console.ReadLine());

            Console.WriteLine("Started.");

            EventSending s = new EventSending();

            for (int i = 0; i < 10 * kbs; i++)
            {
                s.big.Add(s.bytes_100);
            }

            Console.WriteLine("Build message. Total Megabytes: " + ((s.big.Count * 100) / (1000 * 1000)).ToString() + "Megabyte");
            while (true)
            {
                bus.Publish(s);
                Thread.Sleep(delay);
            }
        }
        public PublishSusbcribeCacheManagerBackplane(
            IPublishSubscribe publishSubscribe,
            ILoggerFactory loggerFactory,
            ICacheManagerConfiguration configuration) : base(configuration)
        {
            NotNull(configuration, nameof(publishSubscribe));
            NotNull(loggerFactory, nameof(loggerFactory));
            NotNull(loggerFactory, nameof(loggerFactory));

            _publishSubscribe = publishSubscribe;
            _channelName      = configuration.BackplaneChannelName ?? "CacheManagerBackplane";
            _identifier       = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());

            ILogger logger = loggerFactory.CreateLogger(this);

            _subscription = publishSubscribe
                            .Observe <byte[]>(_channelName)
                            .SelectMany(serializedBackplaneMessage => BackplaneMessage.Deserialize(serializedBackplaneMessage.Data, _identifier))
                            .Subscribe(message =>
            {
                if (logger.IsEnabled(LogLevel.Information))
                {
                    logger.LogInfo("Backplane got notified with new message.");
                }

                switch (message.Action)
                {
                case BackplaneAction.Clear:
                    TriggerCleared();
                    break;

                case BackplaneAction.ClearRegion:
                    TriggerClearedRegion(message.Region);
                    break;

                case BackplaneAction.Changed:
                    if (string.IsNullOrWhiteSpace(message.Region))
                    {
                        TriggerChanged(message.Key, message.ChangeAction);
                    }
                    else
                    {
                        TriggerChanged(message.Key, message.Region, message.ChangeAction);
                    }

                    break;

                case BackplaneAction.Removed:
                    if (string.IsNullOrWhiteSpace(message.Region))
                    {
                        TriggerRemoved(message.Key);
                    }
                    else
                    {
                        TriggerRemoved(message.Key, message.Region);
                    }

                    break;
                }
            });
        }
        public static IDisposable EnableDistributedBackplane(this IWampHostedRealm realm,
                                                             IPublishSubscribe publishSubscribe)
        {
            ConcurrentDictionary <string, IDisposable> disposables = new ConcurrentDictionary <string, IDisposable>();

            AtomicBoolean disableInternalPublishAtomicBoolean = new AtomicBoolean();
            string        forwarderPubSubTopic = $"DistributedRealm_{realm.Name}";
            string        selfId = $"{System.Diagnostics.Process.GetCurrentProcess().Id}_{Environment.MachineName}";

            void TopicCreated(object sender, WampTopicCreatedEventArgs args)
            {
                IDisposable subscription = args.Topic
                                           .Subscribe(new PubSubForwarderWampRawTopicRouterSubscriber(selfId, forwarderPubSubTopic, args.Topic, publishSubscribe, disableInternalPublishAtomicBoolean));

                disposables.TryAdd(args.Topic.TopicUri, subscription);
            }

            void TopicRemoved(object sender, WampTopicRemovedEventArgs args)
            {
                if (disposables.TryGetValue(args.Topic.TopicUri, out IDisposable subscription))
                {
                    subscription.Dispose();
                }
            }

            realm.TopicContainer.TopicCreated += TopicCreated;
            realm.TopicContainer.TopicRemoved += TopicRemoved;

            PublishOptions defaultPublishOptions = new PublishOptions();
            IDisposable    pubSubSubscription    = publishSubscribe
                                                   .Observe <ForwardedWampMessage>(forwarderPubSubTopic)
                                                   .Where(tuple => !selfId.Equals(tuple.Data.PublisherId))
                                                   .Subscribe(_ =>
            {
                disableInternalPublishAtomicBoolean.FalseToTrue();
                try
                {
                    if (_.Data.ArgumentsKeywords == null &&
                        _.Data.Arguments == null)
                    {
                        realm.TopicContainer.Publish(WampObjectFormatter.Value, defaultPublishOptions, _.Data.WampTopic);
                    }
                    else
                    {
                        if (_.Data.ArgumentsKeywords == null)
                        {
                            realm.TopicContainer.Publish(WampObjectFormatter.Value,
                                                         defaultPublishOptions,
                                                         _.Data.WampTopic,
                                                         _.Data.Arguments);
                        }
                        else
                        {
                            realm.TopicContainer.Publish(WampObjectFormatter.Value,
                                                         defaultPublishOptions,
                                                         _.Data.WampTopic,
                                                         _.Data.Arguments,
                                                         _.Data.ArgumentsKeywords);
                        }
                    }
                }
                finally
                {
                    disableInternalPublishAtomicBoolean.TrueToFalse();
                }
            });

            return(new AnonymousDisposable(() =>
            {
                pubSubSubscription.Dispose();
                realm.TopicContainer.TopicCreated -= TopicCreated;
                realm.TopicContainer.TopicRemoved -= TopicRemoved;
                foreach (KeyValuePair <string, IDisposable> pair in disposables)
                {
                    pair.Value.Dispose();
                }
            }));
        }
Exemple #18
0
 public PublishSubscribeHubLifetimeManager(IPublishSubscribe publishSubscribe)
 {
     _publishSubscribe = publishSubscribe ?? throw new ArgumentNullException(nameof(publishSubscribe));
     Setup();
 }
Exemple #19
0
 public TestGrain(IPublishSubscribe publishSubscribe)
 {
     _publishSubscribe = publishSubscribe;
 }