private async Task <HashSet <DierModel> > GetDieren() { HashSet <DierModel> dieren = new HashSet <DierModel>(); GetDierenResponse response = new GetDierenResponse(); try { response = await bus.RequestAsync <GetDierenRequest, GetDierenResponse>(new GetDierenRequest { RequestId = Guid.NewGuid() }); if (response.Success) { dieren = response.Dieren.Select(dier => ConvertToDierModel(dier)).ToHashSet(); //bus.Publish() } } catch (Exception ex) { // uh oh..... Console.WriteLine($"****** Exception occurred: {ex.GetType().FullName}"); Console.WriteLine($"****** Exception message: {ex.Message}"); } return(dieren); }
/* Alternate options: with lots of configuration */ /* private static void SubscribeToBus(IBus bus) * { * // 'RPC style' handler: request - response * bus.RespondAsync<GetDierenRequest, GetDierenResponse>(HandleGetDierenRequestAsync, (config) => { * config.WithPrefetchCount(5); * config.WithQueueName("RPCqueue"); * }); * * // Subscribe to event (with or without topic) * bus.SubscribeAsync<DierCreated>("supskripsjun", HandleDierCreatedAsync, (config) => { * config.WithAutoDelete(true); * config.AsExclusive(); * config.WithQueueName("kjoeneem"); * config.WithPrefetchCount(10); * config.WithTopic("toppique"); * }); * * // Set up receive queue for handling a command * bus.Receive<CreateDier>("CreateDierQueue", HandleCreateDierAsync, (config) => { * config.AsExclusive(); * config.WithPrefetchCount(15); * config.WithPriority(5); * }); * } */ private static Task <GetDierenResponse> HandleGetDierenRequestAsync(GetDierenRequest request) { GetDierenResponse response = new GetDierenResponse { CorrelationId = request.RequestId, Success = request.RequestId != Guid.Empty }; if (response.Success) { /* BREAKING API CHANGE */ //response.Dieren = new System.Collections.ObjectModel.Collection<string> { "break1", "break2" }; foreach (var dier in DierenProvider.GetDieren()) { response.Dieren.Add(dier); } } return(Task.FromResult(response)); }