Esempio n. 1
0
        private void DeliverMessage(RpcRequest request)
        {
            var properties = new BasicProperties
            {
                Type          = typeNameSerializer.Serialize(request.GetType()),
                CorrelationId = "the_correlation_id",
                ReplyTo       = conventions.RpcReturnQueueNamingConvention()
            };

            var body = serializer.MessageToBytes(typeof(RpcRequest), request);

            var waiter = new CountdownEvent(2);

            mockBuilder.EventBus.Subscribe <PublishedMessageEvent>(x => waiter.Signal());
            mockBuilder.EventBus.Subscribe <AckEvent>(x => waiter.Signal());

            mockBuilder.Consumers[0].HandleBasicDeliver(
                "consumer tag",
                0,
                false,
                "the_exchange",
                "the_routing_key",
                properties,
                body
                );

            if (!waiter.Wait(5000))
            {
                throw new TimeoutException();
            }
        }
Esempio n. 2
0
        private void DeliverMessage(RpcRequest request)
        {
            var properties = new BasicProperties
            {
                Type          = TypeNameSerializer.Serialize(request.GetType()),
                CorrelationId = "the_correlation_id",
                ReplyTo       = Conventions.RpcReturnQueueNamingConvention()
            };

            var body = Serializer.MessageToBytes(request);

            mockBuilder.Consumers[0].HandleBasicDeliver(
                "consumer tag",
                0,
                false,
                "the_exchange",
                "the_routing_key",
                properties,
                body
                );

            WaitForResponse();
        }
        /// <summary>
        /// Send a JSON-RPC call to a localhost neblio-Qt or nebliod node Call any Neblio RPC command from the Neblio API libraries. Useful for signing transactions with a local node and other functions. Will not work from a browser due to CORS restrictions. Requires a node to be running locally at 127.0.0.1
        /// </summary>
        /// <exception cref="Neblio.API.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="rpcRequest"></param>
        /// <returns>Task of ApiResponse (RpcResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <RpcResponse> > JsonRpcAsyncWithHttpInfo(RpcRequest rpcRequest)
        {
            // verify the required parameter 'rpcRequest' is set
            if (rpcRequest == null)
            {
                throw new ApiException(400, "Missing required parameter 'rpcRequest' when calling JSONRPCApi->JsonRpc");
            }

            var    localVarPath         = "/";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (rpcRequest != null && rpcRequest.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(rpcRequest); // http body (model) parameter
            }
            else
            {
                localVarPostBody = rpcRequest; // byte array
            }

            // authentication (rpcAuth) required
            // http basic authentication required
            if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password))
            {
                localVarHeaderParams["Authorization"] = "Basic " + ApiClient.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password);
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("JsonRpc", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <RpcResponse>(localVarStatusCode,
                                                 localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                                                 (RpcResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(RpcResponse))));
        }