private async Task <HashSet <AapModel> > GetApen() { HashSet <AapModel> apen = new HashSet <AapModel>(); GetApenResponse response = new GetApenResponse(); try { response = await bus.RequestAsync <GetApenRequest, GetApenResponse>(new GetApenRequest { RequestId = Guid.NewGuid() }); if (response.Success) { apen = response.Apen.Select(aap => ConvertToAapModel(aap)).ToHashSet(); //bus.Publish() } } catch (Exception ex) { // uh oh..... Console.WriteLine($"****** Exception occurred: {ex.GetType().FullName}"); Console.WriteLine($"****** Exception message: {ex.Message}"); } return(apen); }
/* Alternate options: with lots of configuration */ /* private static void SubscribeToBus(IBus bus) * { * // 'RPC style' handler: request - response * bus.RespondAsync<GetApenRequest, GetApenResponse>(HandleGetApenRequestAsync, (config) => { * config.WithPrefetchCount(5); * config.WithQueueName("RPCqueue"); * }); * * // Subscribe to event (with or without topic) * bus.SubscribeAsync<AapCreated>("supskripsjun", HandleAapCreatedAsync, (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<CreateAap>("CreateAapQueue", HandleCreateAapAsync, (config) => { * config.AsExclusive(); * config.WithPrefetchCount(15); * config.WithPriority(5); * }); * } */ /*private static Task<GetApenResponse> HandleGetApenRequestAsync(GetApenRequest request) * { * GetApenResponse response = new GetApenResponse { CorrelationId = request.RequestId }; * * if (request.RequestId != Guid.Empty) * { * foreach (var aap in ApenProvider.GetApen()) response.Apen.Add(aap); * response.Success = true; * } * else * { * response.ErrorMessage = "Received request without correlation identifier"; * } * * return Task.FromResult(response); * }*/ private static Task <GetApenResponse> HandleGetApenRequestAsync(GetApenRequest request) { GetApenResponse response = new GetApenResponse { CorrelationId = request.RequestId, Success = request.RequestId != Guid.Empty }; if (response.Success) { foreach (var aap in ApenProvider.GetApen()) { response.Apen.Add(aap); } } return(Task.FromResult(response)); }