I write a .proto file, and it include a service:
service ServerService {
rpc HelloServer (Word) returns (Void);
}
Then, I use protobuf-net generate .cs file:
public interface IServerService
{
gt.Void HelloServer(gt.example.Word request);
}
But I do not know how to use it. Is there any doc?
A new standard, gRPC, is picking up steam and has support in .net core.
Check out this tutorial: https://learn.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.1&tabs=visual-studio
The tutorial also links out to other information on gRPC in .NET. The docs are pretty good.
Related
Im using .NET 6 and Autofac to register my dependencies, all works great.
However I was wondering how can I register a healthcheck in my module (not in the startup.cs), ex:
public class InfrastructureModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<ApplicationDbContext>().InstancePerLifetimeScope();
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerLifetimeScope();
// builder.AddCheck<MyServiceHealthCheck>("Service ACheck"); <- not working
}
}
Short answer is: you can't. You can't mix and match Microsoft registrations with Autofac registrations like that. That's why there's ConfigureServices separate from ConfigureContainer.
Longer answer is: if you want to go spelunking through the code of AddHealthCheck and figure out what it's doing under the covers, you could make your own Autofac version of that and it would work. But it's work for you to do, not something Autofac provides, and it'd be supported only by you.
However, reading the intent of the question, it sounds like you want to do MS registrations in an Autofac module and that's not a supported thing.
I am following the guide of the new quarkus-resteasy-reactive-jackson extension to use it in an existing Quarkus application deployed in production.
In the Custom headers support section it's introduced the ClientHeadersFactory interface to allow injecting headers in a request, but you are forced to return a sync response. One can not use Uni<MultivaluedMap<String, String>>, which is of what is desired in my case, because I need to add a token in the header, and this token is retrieved by a request to another rest endpoint that returns a Uni<Token>.
How can I achieve this in the new implementation? If not possible, is there a workaround?
It's not possible to use Uni<MultivaluedMap<...>> in ClientHeadersFactory in Quarkus 2.2.x (and older versions). We may add such a feature in the near future.
Currently, you can #HeaderParam directly. Your code could probably look as follows:
Uni<String> token = tokenService.getToken();
token.onItem().transformToUni(tokenValue -> client.doTheCall(tokenValue));
Where the client interface would be something like:
#Path("/")
public interface MyClient {
#GET
Uni<Foo> doTheCall(#HeaderParam("token") String tokenValue);
}
I'm wondering if there is smth like a custom data binder (from Spring MVC) or custom model binder (from ASP.NET MVC )
in the grpc framework?
The goal is to be able to convert a protobuf object (i.e. request, transport-level DTO) into a domain entity.
E.g. instead of this code in my service implementation:
public void createCustomer(Protobuf.CreateCusomerRequest request) {...}
I want to be able to say:
public void createCustomer(Domain.CreateCusomerCommand command) {...}
Provided I have a custom converter Protobuf.CreateCusomerRequest -> Domain.CreateCusomerCommand I want to plug it into the grpc pipeline so that the runtime would call that converter to convert the request into command and then call the service passing the command instead of the request.
Any ideas are welcome.
What we did is that we implemented our own protoc compiler plugin that knows how to convert transport message to entity message. So implementation of the service looks like domainService.persist(protoRequestMessage.toDomainObject() )
The day will come and it will become open source :-)
I am planning to implement Graphql in my spring boot application. I Googled many sites for Graphql server setup in Java and came across two ways of doing it .
One is implementing GraphQlResolver like below
public class MyResolver implements GraphQLResolver<ModelX>
and another one is by Implementing Datafetcher
Reference: https://www.graphql-java.com
#Component
public class MyDataFetcher implements DataFetcher<ModelX> {
#Override
public ModelX get(DataFetchingEnvironment environment) {
// TODO Auto-generated method stub
}
}
Please provide some information on differences in both the approaches and best among them
DataFetcher is from graphql-java library , the only GraphQL Java implementation that I known in Java world so far.
GraphQLResolver is from another library called graphql-java-tools which is built on top of graphql-java . You can think that it provides a way which allow you to build a GraphQL server in a more high level way or a way that you may find more convenient. At the end , GraphQLResolver will somehow invoke DataFetcher#get() for resolving the value for a field.
An similar analogy in Spring is that graphql-java like Servlet while graphql-java-tools like SpringMVC.
The term "resolver" is a general GraphQL term and is agnostic of any specific GraphQL implementation/framework/language. Each field in GraphQL is backed by a function called the resolver which is provided by the GraphQL server developer. In short, the resolver is the first logic hit to map any specific field to any specific response.
The Netflix DGS library is now open source (as of late 2020) and it introduced "DataFetchers". DataFetchers, in the DGS world, are simply a DGS-specific way of implementing resolvers.
Reading:
Netflix DGS Resolvers
I have written an API Bundle and some implementing services.
Now i want to use them as plugins, so first of all i need a list of all the services i have.
I'm starting the api like this:
Framework m_fwk = new org.apache.felix.framework.FrameworkFactory().newFramework(null);
m_fwk.init();
AutoProcessor.process(null, m_fwk.getBundleContext());
m_fwk.start();
Bundle api = m_fwk.getBundleContext().installBundle(
"file:/foo/bar/api/target/api-1.0.jar");
api.start();
So now the API is loaded. Now i need to know which bundles implements this API, how can i get this information from the framework?
It sounds like you're trying to re-implement the OSGi service registry. Have a look at Blueprint or Declarative Services instead. At the very least I'd suggest using the OSGi service API to register and consume services.
You only seem to load an API bundle, I guess you want to install other bundles for the implementations? Most people then load a director or so:
for ( File b : bundles.listFiles() ) {
ctx.installBundle( b.toURI().toURL() );
}
Each of these bundle should look like (using DS):
#Component
public class Impl implements API {
public whatever() { ... }
}
The bundle collecting the services could look like:
#Component
public class Collector {
#Reference(type='*')
void addAPI( API api ) { ... }
void removeAPI( API api ) { ... }
}
This is done with the bnd annotations for DS (see bndtools for examples). However, you can also implement/collect the services in Blueprint, iPojo, and many other helpers.
Given that a Framework is also a Bundle, you can get a BundleContext that allows you to find all services you need. You could do something like
m_fwk.getBundleContext().getServiceReferences("com.example.MyInterface", null)
to get all implementers of a given service.
However, you should be aware that you are living in a different classloader than the inhabitants of your framework are.