Is there any sample code / help for inter service communication using grpc in quarkus.
We have 2 services. we want to expose one service api to other service.
I have included all the dependency and I have created proto file, i have to keep protofile in both client and server? or we have to make common project to store proto file and communicate both service from there.
Check the following documentation and examples:
https://quarkus.io/guides/grpc-getting-started
https://quarkus.io/guides/grpc-service-implementation
https://quarkus.io/guides/grpc-service-consumption
Example: https://github.com/quarkusio/quarkus-quickstarts/tree/main/grpc-plain-text-quickstart
Example: https://github.com/quarkusio/quarkus-quickstarts/tree/main/grpc-tls-quickstart
https://quarkus.io/blog/quarkus-grpc/
One important aspect is that with gRPC what you share is the proto file. So yes, you will either duplicate it or package it in a shared artifact.
Related
The use case is that I need to poll a folder on a remote server, and if a new file is copied to that folder, I need to call a REST get API with the file contents. The REST API will process the file contents using Spring batch.
I am trying to use Spring boot integration for that purpose but having issues finding my way. Is Spring Integration best suited for this purpose? If yes, can I have a simple example of just the Spring Integration picking up the file and calling the REST API?
Or can I simply use the Java Watcher service?
Not clear what is your remote folder, but you can't use Java WatchService for that purpose anyway. Typically the remote directory is on an (S)FTP. Spring Integration provides channel adapters to poll such a remote directory under the mentioned protocol.
See more info in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html#ftp-inbound
You probably don't need to have a local copy of a remote service, then you can consider to use a streaming channel adapter instead: https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html#ftp-streaming
As far as a file content is emitted into a channel configured in that channel adapter, you can use an HTTP Outbound Channel Adapter to call some REST API: https://docs.spring.io/spring-integration/docs/current/reference/html/http.html#http-outbound
You can investigate samples project for some inspiration: https://github.com/spring-projects/spring-integration-samples
I've been reading through the nameko docs, and it is all good and clear, except for one part.
How do you actually deploy your nameko microservice?
I mean, it is clear how we deploy RESTful APIs in flask_restful, for instance. But with nameko?
If two microservices should communicate, how do we move them into the "listening" state?
I am not sure I understand your problem.
For each nameko service you define AMQP_URI constant that point to your RabbitMQ instance.
If each of your services have the same AMQP_URI, it make possible communication through sending rpc calls (where you have a queue per service endpoint) or using pub/sub messaging because service use the same RabbitMQ instance.
You can also have HTTP REST API. You must define endpoint in nameko service with http decorator (see example here: https://nameko.readthedocs.io/en/stable/built_in_extensions.html). In your confguration you have to define PORT for you web server, e.g. port 8000: WEB_SERVER_ADDRESS: 0.0.0.0:8000. And make this port accessible for the World.
I have two spring projects. One project having web-socket implementation which sends messages to the client and second project have some other services and classes. Before in the client side, I am defining two proxies. One for main services, another one for receiving web-socket messages and I have to run both the projects on different-different ports. Now I want both the projects to run on the same port. Is there any way to do that. I also have a doubt that once first project is hosted on a port ( suppose 8080 ), will web-socket push notification work properly on the same port?
While it is not possible to run both projects on same port there are other ways you can achieve this. You can use a gateway (For ex: kong) service or package your applications and deploy on a tomcat server. I prefer deploying applications to tomcat (If you don't have many services) as you need to put extra efforts to maintain gateway.
I am trying to introduce Pact in our company. However the consumer calls APIs using providers SDKs and the host-port is dynamically determined using Kubernetes. I am new to all this backend technology so trying to understand how do we deal with this since it will be impossible to get host/port into pom.xml if its dynamic?
It depends whether you're talking about port of the mock service in the consumer tests, or the port of the provider in the verification step.
In the consumer tests, is it possible to provide a test implementation of the part of the SDK that looks up the port? Perhaps you could contact the provider team to see they could supply one that would allow you to set a known port?
In regards to the provider, you would typically run the verification step against a locally running provider in the CI build, not against one deployed into a live environment, so a known port should be able to be used.
I'm implementing the TCP client using the Spring Integration.
The requirements are:
1. Through the UDP connection (from somewhere) receive the ip or host address of the TCP server.
2. Open TCP connection to the server, to the destination host from previous step and send some business data to this server.
I use the Spring Integration framework, version "2.2.0.RELEASE", and the problem is that in the default configuration of the tcp-connection-factory the host attribute should be "hardcoded" in xml. For example:
<ip:tcp-connection-factory id="client" type="client" host="localhost" port="1234" single-use="true"/>
The question is how to avoid the static definition of the destination host in application context, and be able to 'lazy' initialise the tcp-connection-factory when the destination host will be known.
I know that this flow could be easily implemented by the standard Network APIs of Java, and the question is specific about the Spring-Integration API
At this time, the configuration is static.
You could however use a similar technique to that used in the dynamic ftp sample which configures ftp outbound adapters at runtime.
As far as <int-ip:tcp-connection-factory> provides some instance of AbstractConnectionFactory. And from other side <int-ip:tcp-outbound-channel-adapter> applies that instance via connection-factory, so, there is no stops to implement your own RoutingConnectionFactory.
The implementation may rely on some value from ThreadLocal. The idea is here:
https://github.com/spring-projects/spring-amqp/blob/master/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java,
https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java
It's not currently possible/easy - even if you customize or extend the class for tcp-connection-factory to be able to connect to changing hosts. There is an open new feature request in JIRA to provide this functionality.