binarythistle / s04e03---.net-microservices-course- Goto Github PK
View Code? Open in Web Editor NEWCode for the Introduction to .NET Microservices
Code for the Introduction to .NET Microservices
Hey! Great Course BTW.
There is one thing I found so cumbersome that I had to go out of my way to fix it on my project, the commenting/uncommenting for migration to use SqlServer.
Here's how I handled it (note, my project is a "no startup" project, so some minor adaptation would be required in Startup).
In Program.cs
var dbProvider = builder.Configuration.GetValue("Provider", "InMemory");
if(builder.Environment.IsProduction() || dbProvider == "SqlServer") {
// AddDbContext using SqlServer Database
} else {
// AddDbContext using InMemory Database
}
When generating migrations
dotnet ef Migrations add {MigrationName} -- --provider SqlServer
where {MigrationName}
is the name of the migration you want to add.
Such a simple fix to avoid commenting/uncommenting every times you want to add a migration I thought I would share.
Current name of method is RabbitMQ_ConnectionShitDown
. May I suggest RabbitMQ_ConnectionShutDown
.
BTW, thanks for a great tutorial.
I came across some problems while trying to create this project myself here is a solution
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build-env /app/out .
RUN sed -i 's/CipherString = DEFAULT@SECLEVEL=2/CipherString = DEFAULT@SECLEVEL=1/g' /etc/ssl/openssl.cnf
ENTRYPOINT ["dotnet", "UserService.dll"]
It is the first change more about it in dotnet/SqlClient#633
Second one is adding TrustServerCertificate=true;
to your connection string aka "PlatformsConn" in this project
For now those are all the errors i have spotted i will post more if i find any.
In the tutorial, I set the hostname to "acme.com" in ingress-srv.yaml and applied it. However, when I tried to access it, it was inaccessible even after I changed the default IIS port. Upon listing services in the ingress namespace, I attempted to access the host using "acme.com:31348/api/platforms" and it worked. Is this behavior normal? How can I access it using the default port (80)?
Hi,
I'm getting 404 error while trying to connect (acme.com/api/platform) platform service from Ingress, but can able to connect with NodePort (localhost:3xxxx/api/platform).
after researching in Internet and apply many troubleshooting I feel like Ingress cannot able to connect with the Platform-ClusterIp-srv (correct me if im wrong)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: acme.com
http:
paths:
- path: /api/platform
pathType: Prefix
backend:
service:
name: platforms-clusterip-srv
port:
number: 80
- path: /api/c/Platform
pathType: Prefix
backend:
service:
name: commands-clusterip-srv
port:
number: 80`
apiVersion: apps/v1
kind: Deployment
metadata:
name: platforms-depl
spec:
replicas: 1
selector:
matchLabels:
app: platformservice
template:
metadata:
labels:
app: platformservice
spec:
containers:
- name: platformservice
image: virtualking/platformservice
apiVersion: v1
kind: Service
metadata:
name: platforms-clusterip-srv
spec:
type: ClusterIP
selector:
app: platformservice
ports:
- name: platformservice
protocol: TCP
port: 80
targetPort: 80
Note: In tutorial, he used v0.48.1 Ingress.
I used this v1.0.4. https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.4/deploy/static/provider/cloud/deploy.yaml
For those like me that went the MSSQL route on the CommandsService Project instead of keeping it in memory, you will most likely run into an issue with inserting a platform in the EventProcessor that does not happen when using in memory.
The mapping used for PlatformPublishedDto
CreateMap<PlatformPublishedDto, Platform>()
.ForMember(dest => dest.ExternalId, opt => opt.MapFrom(src => src.Id));
while mapping the PlatformService's PlatformPublishedDto.Id
to a CommandsService's PlatformPublishedDto.ExternalId
, it will leave the same PlatformService's PlatformPublishedDto.Id
also mapped to the CommandsService's PlatformPublishedDto.Id
That will cause MSSQL to complain about inserting with an explicit IDENTITY.
To fix this, you have to tell AutoMapper to ignore Id
on the destination like below:
CreateMap<PlatformPublishedDto, Platform>()
.ForMember(dest => dest.ExternalId, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Id, opt => opt.Ignore());
After this command , we should get 1/1 but I am not getting , then I check using kubectl describe pod <pod_name> and I got following error: Failed to pull image "aero016/plateformservice:latest": rpc error: code = Unknown desc = Error response from daemon: pull access denied for aero016/plateformservice, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
After getting this error I have logged in using docker login
and still I am getting error then I have checked that my image is present or not , my image also present and also my image is public . So now can anyone help me about this issue??? And also I have tried to pull image locally using docker pull
and It is working fine but I am getting this error>>>
Until now, everything has worked ouy fine, but I have been trying to set the loadbalancer working so I can access the MSQL from thr managment studio but the externalIP is pending, any help
Building...
--> Calling GRPC Service https://localhost:5001
--> Couldnot call GRPC Server Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.", DebugException="System.Net.Http.HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while unable to establish HTTP/2 connection.
at System.Net.Http.HttpConnectionPool.ThrowGetVersionException(HttpRequestMessage request, Int32 desiredVersion)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Grpc.Net.Client.Internal.GrpcCall2.RunCall(HttpRequestMessage request, Nullable
1 timeout)")
Seeding new platforms...
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at CommandsService.Data.PrepDb.SeedData(ICommandRepo repo, IEnumerable`1 platforms) in /Users/Project/PS/CommandsService/Data/PrepDb.cs:line 28
at CommandsService.Data.PrepDb.PrepPopulation(IApplicationBuilder applicationBuilder) in /Users/Project/PS/CommandsService/Data/PrepDb.cs:line 20
at Program.
Sending HTTP request POST http://localhost:6000/api/c/platforms/
--> Could not send synchronously : The SSL connection could not be established, see inner exception.
--> inner exception. : The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot
PlatformService container's logs:
{"EventId":100,"LogLevel":"Information","Category":"System.Net.Http.HttpClient.ICommandDataClient.LogicalHandler","Message":"Start processing HTTP request POST http://commands-clusterip-srv/api/commands/platforms/","State":{"Message":"Start processing HTTP request POST http://commands-clusterip-srv/api/commands/platforms/","HttpMethod":"POST","Uri":"http://commands-clusterip-srv/api/commands/platforms/","{OriginalFormat}":"Start processing HTTP request {HttpMethod} {Uri}"}}
{"EventId":100,"LogLevel":"Information","Category":"System.Net.Http.HttpClient.ICommandDataClient.ClientHandler","Message":"Sending HTTP request POST http://commands-clusterip-srv/api/commands/platforms/","State":{"Message":"Sending HTTP request POST http://commands-clusterip-srv/api/commands/platforms/","HttpMethod":"POST","Uri":"http://commands-clusterip-srv/api/commands/platforms/","{OriginalFormat}":"Sending HTTP request {HttpMethod} {Uri}"}}
{"EventId":101,"LogLevel":"Information","Category":"System.Net.Http.HttpClient.ICommandDataClient.ClientHandler","Message":"Received HTTP response headers after 90.6421ms - 404","State":{"Message":"Received HTTP response headers after 90.6421ms - 404","ElapsedMilliseconds":90.6421,"StatusCode":404,"{OriginalFormat}":"Received HTTP response headers after {ElapsedMilliseconds}ms - {StatusCode}"}}
{"EventId":101,"LogLevel":"Information","Category":"System.Net.Http.HttpClient.ICommandDataClient.LogicalHandler","Message":"End processing HTTP request after 103.0619ms - 404","State":{"Message":"End processing HTTP request after 103.0619ms - 404","ElapsedMilliseconds":103.0619,"StatusCode":404,"{OriginalFormat}":"End processing HTTP request after {ElapsedMilliseconds}ms - {StatusCode}"}}
Exception Caught!
Sync POST to CommandsService failed!
Message :Response status code does not indicate success: 404 (Not Found).
SendPlatformToCommand:
public async Task SendPlatformToCommand(PlatformReadDto platform)
{
try
{
var httpContent = new StringContent(
JsonSerializer.Serialize(platform),
Encoding.UTF8,
"application/json"
);
// var response = await _httpClient.PostAsync($"{_configuration["CommandService"]}", httpContent);
// if (response.IsSuccessStatusCode)
// {
// Console.WriteLine("Sync POST to CommandsService success!");
// }
// else
// {
// Console.WriteLine("Sync POST to CommandsService failed!");
// }
HttpResponseMessage response = await _httpClient.PostAsync($"{_configuration["CommandService"]}", httpContent);
response.EnsureSuccessStatusCode();
Console.WriteLine("Sync POST to CommandsService success!");
}
catch (HttpRequestException ex)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Sync POST to CommandsService failed!");
Console.WriteLine("Message :{0} ", ex.Message);
}
Can anyone tell me what the problem is? Thank you.
Can't connect as user sa, its just sending me Login failed for user 'sa' error:18456,
changed line 25 env name in mssql-plat-depl.yaml file from SA_PASSWORD to MSSQL_SA_PASSWORD, but that didn't help either
Then tried to reapply this deployament and restart it by 2 commands:
1) kubectl apply -f mssql-plat-depl.yaml
2) kubectl rollout restart deployment mssql-depl
Who faced similar problem? Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.