[ad_1]
I’m working on a learning project in which I developed 2 APIs Buyer and Seller and containerized it using Docker. To setup communication between these 2 APIs, I wanted to use KubeMQ RPC. I referred their cookbook and wrote a simple SendRequestAsync and SubscribeRequest.
public async Task<Response> SendRequest()
{
Channel = new Channel(new ChannelParameters
{
RequestsType = RequestType.Query,
Timeout = 10000,
ChannelName = "SampleChannel",
ClientID = "MyAPI",
KubeMQAddress = "localhost:50000"
});
var result = await Channel.SendRequestAsync(new KubeMQ.SDK.csharp.CommandQuery.Request
{
Metadata = "MyMetadata",
Body = Converter.ToByteArray("A Simple Request from Buyer.")
});
//Async
if (result.Executed)
return result;
return null;
}
private void SubscribeToChannel()
{
SubscribeRequest subscribeRequest = new SubscribeRequest(SubscribeType.Queries, "MyAPI", "SampleChannel", EventsStoreType.Undefined, 0);
_responder.SubscribeToRequests(subscribeRequest, HandleIncomingRequests, HandleIncomingError);
}
private Response HandleIncomingRequests(RequestReceive request)
{
// Convert the request Body to a string
string strBody = Converter.FromByteArray(request.Body).ToString();
_logger.LogDebug($"Respond to Request. ID:'{request.RequestID}', Channel:'{request.Channel}', Body:'{strBody}'");
// Create the Response object
Response response = new Response(request)
{
Body = Converter.ToByteArray("OK"),
Error = "None",
ClientID = this.ClientID,
Executed = true,
Metadata = "OK",
};
return response;
}
private void HandleIncomingError(Exception ex)
{
_logger.LogWarning($"Received Exception :{ex}");
}
My docker.yaml reads as below
services:
kubemq:
image: kubemq/kubemq:latest
container_name: kubemq
ports:
- "8080:8080"
- "9090:9090"
- "50000:50000"
environment:
- KUBEMQ_HOST=kubemq
- KUBEMQ_TOKEN=<<MyToken>>
networks:
- backend
volumes:
- kubemq_vol:/store
networks:
backend:
volumes:
kubemq_vol:
I am simply trying to send a message and get a response. But I’m getting the below error:
Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="failed to connect to all addresses", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1654251803.063997885","description":"Failed to pick subchannel","file":"/var/local/git/grpc/src/core/ext/filters/client_channel/client_channel.cc","file_line":5420,"referenced_errors":[{"created":"@1654251803.063991635","description":"failed to connect to all addresses","file":"/var/local/git/grpc/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":398,"grpc_status":14}]}")
at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg)
at Grpc.Core.Calls.BlockingUnaryCall[TRequest,TResponse](CallInvocationDetails`2 call, TRequest req)
at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request)
at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx)
at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation)
I’m new to docker, KubeMQ and Microservices. So I’m maybe doing something wrong here. Any inputs is appreciated.
I didn’t find a lot of articles/questions on KubeMQ when compared to Kafka or RabbitMQ. I have to continue using KubeMQ since I can’t change the requirement now.
[ad_2]