I am working on Vert.x Service Discovery registering HttpEndPoints. Is there a way to specify ProxyOptions when publishing HttpEndPoint to service discovery?
Thanks,
-Rajani
You don't provide the options when creating the record but when retrieving the service reference.
ServiceReference reference = discovery.getReferenceWithConfiguration(record, new HttpClientOptions()
.setProxyOptions(proxyOptions)
.toJson());
This explained in the retrieving a service reference section of the documentation:
When retrieving a service reference you can pass a JsonObject used to
configure the service object.
Related
We have an asp.net core Web API and registering our EF DB context like so
services
.AddDbContext<SiteDbContext>((serviceProvider, opt) =>
{
opt
.UseNpgsql(options.Site)
.UseInternalServiceProvider(serviceProvider)
;
})
The DB Context calls DbContextOptionsBuilder.UseLoggerFactory which fails.
Looking at this doco https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.useloggerfactory?view=efcore-5.0
It is mentioned that you can't do what I just did above and suggested to "In this case, the ILoggerFactory should be configured directly in that service provider."
My question is how is that specifically done? to configure directly in that service provider.
From the docs (emphasis mine):
Sets the IServiceProvider that the context should resolve all of its services from. EF will create and manage a service provider if none is specified.
The service provider must contain all the services required by Entity Framework (and the database being used). The Entity Framework services can be registered using an extension method on IServiceCollection. For example, the Microsoft SQL Server provider includes an AddEntityFrameworkSqlServer() method to add the required services.
You shouldn't try to replace the internal service provider with the app-level service provider unless you register every single internal service EF core needs.
If you actually need to set the logger factory, there's an easier way to configure it. Use an overload that gives you an IServiceProvider:
services.AddDbContext<AppDbContext>((provider, options) =>
{
var loggerFactory = provider.GetRequiredService<ILoggerFactory>();
options
.UseNpgsql(/* ... */)
.UseLoggerFactory(loggerFactory);
});
I use springcloud to build the system, including many microservices。 For some interface calls, I use resttemplate annotated by #LoadBalance to implement load balancing, and use eureka as a registry center. However, when I call interfaces between different micro services, resttemplate sometimes will connect to wrong service. For example, I have service A, B, C, when service A call a service B's interface, resttemplate annotated by #LoadBalance will find the actual ip&port from eureka by service name first, and then build the actual url and send the request to target server, but sometimes, it will find the service C's ip&port when I call service B's interface, which cause a fail invoking. This case occurs infrequently but nerver disappear, I have been troubled for a long time, could anyone give me some suggestions? Thanks.
I learned why yesterday: it is a bug in spring cloud Dalston.RELEASE(https://github.com/spring-cloud/spring-cloud-commons/issues/224), and we happen to use this version. Spring cloud had fixed this bug in Dalston.SR2, and now it works fine
I have integrated Light Inject in web api project. I am able to register service successfully in application_start in global.asax. I am using filter which needs to be registered as well in application_start in global.asax. Filter constructor have reference to the services registered however I am not able to get the service instance. Samplee code:
service registration is as below:
container.Register<ILogger, EPPSLogger>(GetLifetime());
filter registration needs instance of ILogger. Using below code:
config.Filters.Add(new EPPSAuthenticationFilter(
config.DependencyResolver.GetService<ILogger>(),
config.DependencyResolver.GetService<IAuthenticationSecrets>()));
gets the error when try to getService that lightinject module is not injected/registered. I cant upgrade to .net framework 4.5 or so.
Any help is highly appreciated.
Thanks
When Spring Cloud Eureka instance starts I can define some instance metadata statically (in eureka.instance.metadataMap.* in my application.yml) or dynamically (using EurekaInstanceConfigBean for example). But once instance is registered, this metadata no longer updates in Eureka after I update the config bean.
Is there a way to define some metadata that will dynamically update in Eureka? So Eureka will work kind of like a key-value storage for each instance.
If you want to update any metadata from eureka client for itself, just use com.netflix.appinfo.ApplicationInfoManagerobject and call registerAppMetadata(Map<String, String>).
If so, this info will be updated in Eureka Server usually soon or at least in 30sec.You can use DI to get the instance of ApplicationInfoManger.
If you want to update metadata for other service instance, just invoke REST API like below to eureka server.
PUT /eureka/apps/appID/instanceID/metadata?key=value
I am trying to find my stateless service using IServiceProxyFactory CreateServiceProxy method. It seems to find the service instance but when I invoke a method it gets an error "Client is trying to connect to invalid address net.tcp://localhost...". The stateless service uses WcfCommunicationListener.
The default implementation of IServiceProxyFactory is ServiceProxyFactory, that creates an instance of FabricTransportServiceRemotingClientFactory which in turn gives you an FabricTransportServiceRemotingClient. This one communicates (as the name suggests) using Fabric transport over TCP. Fabric transport expects the Service to have a fabric transport listener FabricTransportServiceRemotingListener on a address like fabric:/applicationname/servicename.
If you want to connect to your service that is listening to connections using the WcfCommunicationListener then you need to connect to it using WcfCommunicationClient that you can create like this:
// Create binding
Binding binding = WcfUtility.CreateTcpClientBinding();
// Create a partition resolver
IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault();
// create a WcfCommunicationClientFactory object.
var wcfClientFactory = new WcfCommunicationClientFactory<IMyService>
(clientBinding: binding, servicePartitionResolver: partitionResolver);
var myServiceClient = new WcfCommunicationClient(
wcfClientFactory,
ServiceUri,
ServicePartitionKey.Singleton);
The above sample is from the documentation https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-wcf
So, either change your service to use fabric transport if you want to use ServiceProxy to create a client, or change your client side to use WcfCommunicationClient instead.