Need an example of using design by contract in Symfony - symfony

I am trying to build an API proxy for an external API in my Symfony app. So my Symfony app uses design by contract principle. So a backend service to query the external API.
I need to use "coding by contract" principle with an interface so that the API is easily exchangeable with other services.
I am looking for an example which illustrates this concept.

Related

Generate clients for apis with #Hidden annotations via openapi-generator

I'm using swaggerCodegen to generate Apis clients for a Spring based application using org.openapitools.openapi-generator-cli. I marked some operations with #io.swagger.v3.oas.annotations.Hidden. Swagger codegen is not generating client stubs for these. Is there a config to hide them in the Swagger documentation, but still generate client code?

Mocking with Serverless Offline and Integration Tests

I have a Serverless stack (AWS) using API Gateway authentication and a Lambda, implementing a restful API using NestJS.
I'm using Serverless-offline to simulate the stack in my local environment. This allows me to simulate the API Gateway authentication (simple keys, not custom authorizer) and lambda execution from an end to end API call perspective.
I can use the NestJS test helpers to perform e2e tests, which allows me to inject mocks for other services not available in the stack.
What I'd like to do is use serverless-offline to run the tests - hence allowing me to test authentication via its simulated API Gateway. I can see how I can do this by launching serverless-offline in my tests (e.g. https://dev.to/didil/serverless-testing-strategies-4g92).
BUT, if I use serverless-offline (as link) then I can't see how it would be possible to inject mocks for other services not available in the stack.
Is there another solution for e2e testing that allows me to simulate the api gateway AND inject mocks?
Any help much appreciated!
With the testing strategy you linked you can mock your requests and responses to external services to test different scenarios. Nock is a library that can simplify mocking external requests in your tests.
Although, it seems that this may not be work as a I imagine with serverless-offline. I found this answer that outlines a strategy for replacing endpoints that access external services when running tests.

.Net Core querying records from different microservices

I'm learning how to design and implement microservices using serverless technologies. I'm trying to create autonomous microservices and am having difficulty understanding how to communicate data across/between microservices. I'm using .Net Core for my microservices and am wanting each microservice to be a AWS lambda function exposed via API Gateway.
I have the following scenario:
Institution microservice - returns a list of institutions within a radius (25 miles) of a zipcode.
ROI Calculator microservice - receives a zip code as input and calls institution microservice receiving a list of institutions. For each institution returned, perform a series of calculations yielding a ROI value.
How should ROI Calculator microservice make a call to institution microservice?
ASP.NET core web api application can be published as it is on AWS Lambda as Serverless function. You get everything that regular .NET core application provides like controllers , models etc. Amazon API gateway proxy is integrated directly into .NET Core api routing system. So your AWS lambda function will be serving your .Net core web api. You should watch this tutorial for starters to get better understanding.
Create .NET Core AWS lambda function
.NET core AWS Lambda Microservices
If you go by template provided by AWS SDK (ASP.NET core web api template) and you publish .Net core web api on AWS it will configure everything for you including AWS Lambda function and API gateway. So if you have create 2 .net core web api projects you will have 2 web api gateways. The problem is if we have 10 microservices mean we will have 10 api gateways , so we should ideally have 1 api gateway for multiple microservices.
I have worked on POC recently that has one API gateway and all microservices AWS lambda functions are behind this. Each microservice has base path e.g. shopping or users setup in their startup.cs that will identify them individually behind apigateway. so microservice 1 will be apigateway/shopping/{anything} , another microservice will be apigateway/users/{anything} and they both are configured behind api gateway. API Gateway will send request to AWS lambda function (.Net core web api) and this request will be resolved by .Net core routing system. Even multiple controller can be used this way in a single web api project without problem.
I have modified serverless.template so we can only publish aws lambda function and configure apigateway seperatley. You can find code sample and details on my github blog here .NET Core Web API AWS Lambda Microservices Sample .
There are two ways of doing this depending on your independance of the microservices is probably the best answer:
Make a internal HTTP call from the ROI -> Institution which would be okay. The problem with this is that if the service is down the data will not be available.
Store the data needed to make the calculation inside the ROI service as well. This seems strange but the data once created in say the Institution service it could be sent via a message bus to the ROI service which then uses the data when needed. (this however may not suit your domain, it depends what information it needs).
However it seems that the calculation and the storage of the Institutions could be within the same microservice therefore eleminating the problem.

How to efficiently develop spring-boot microservice that synchronise data in real-time with firestore of google firebase cloud?

The work method Firebase suggests and recommends is to link the Front-End application directly with the FireStore database service, and this provides real-time synchronization between the data in the Front-End application and the documents in FireStore, which is managed by the AdminSDK Firebase.
However, I would like to implement a business layer (following a micro-services architecture) with Spring-boot, but in this case it is up to me to manage the synchronization in real time between my micro-services and the front-end application.
So, How to efficiently develop spring-boot microservice that synchronise data in real-time with firestore of Google Firebase Cloud ?
Which framework or protocole I would use to brige this fonctionality ?
In my opinion, you could pass this by adding fabiomaffioletti (specific connector to firebase -- you could find it on github), you can refactor your entities by changing it to #FirebaseDocument("/people") to the entry point on firebase /people,
This denpendency would give the same actions as a normal repository by creating an interface anotate by repository that can give spring boot the possibility to scan the
repositories
#Repository
public class PeopleRepository extends DefaultFirebaseRealtimeDatabaseRepository<People, long> {
}
Don't forget to add #EnableFirebaseRepositories on your main apllication class.
Finaly on your properties file add this properties to precise the firebase end-point:
firebase.service-account-filename=[classpath|file]:[service-account-filename].json
firebase.realtime-database-url=[realtime database url]
Hope this would help you.
My apologize for my bad english :D

Cloudfoundry actuator endpoints in a .net core console application hosted by GenericHost

I have a question about CloudFoundry actuator endpoints in a .net core console application using Steeltoe. I am planning to use generic host https://jmezach.github.io/2017/10/29/having-fun-with-the-.net-core-generic-host/ to perform some background task. I would like to use few actuator endpoints e.g.Health actuator. I could find samples with WebHost here https://github.com/SteeltoeOSS/Samples/blob/dev/Management/src/AspDotNetCore/CloudFoundry/Startup.cs. The below code needs IApplicationBuilder
// Add management endpoints into pipeline
app.UseCloudFoundryActuators();
So it is possible to use actuator endpoints in a console application which is hosted by generic host. Any samples are most welcome. Thanks in advance.
Steeltoe 3.0 added a variety of extensions for using Management/Actuators with HostBuilder. Check out this file for some examples.
It would also be possible to add another implementation of the actuator endpoints that communicate over something other than HTTP (perhaps RabbitMQ as an example), Steeltoe Management was built with portable base endpoint functionality in mind - but then you would also need a new application for interacting with them, and you wouldn't be able to use them with Apps Manager on PCF.

Resources