public Task <string> Subscribe(string serviceName, string topic, CancellationToken token) { InMemoryTopic inMemoryTopic = _topics.GetOrAdd(topic, t => new InMemoryTopic(t)); string id = inMemoryTopic.Subscribe(serviceName); // This shouldn't fail since each service should only subscribe once to a topic if (_topicBySubscriptionId.TryAdd(id, topic) == false) { throw new InvalidOperationException($"Subscription for service {serviceName} already exists for topic {topic}"); } return(Task.FromResult(id)); }
public Task SendMessage(string topic, byte[] message, CancellationToken token) { InMemoryTopic inMemoryTopic = _topics.GetOrAdd(topic, t => new InMemoryTopic(t)); return(inMemoryTopic.Send(message, token)); }