I am running a couple of services in GAP and I have to assign each service a specific subdomain, which is done from the dispatch.yaml file. So far so good, my query is: Is it enough to define the dispatch.yaml file in a single service or do I have to do it for each one?
You can assign all services to specific subdomains using a single dispatch.yaml file:
- url: "subdomain1.domain.com/*"
service: service1
- url: "subdomain2.domain.com/*"
service: service2
- url: "subdomain3.domain.com/*"
service: service3
#And so on
Related
I want to call a service to Validate(Validation service) before routing the actual request to desired service.
Lets consider two different scenarios:
If the Validation service returns Valid, then call respective service (In this case service A).
If Validation service returns Invalid, then return response bad request to user (No need to call service A)
Please help me finding correct configuration (or coding in which filter) to be done, to call validation service for every request.
We are having three modules Gateway using spring-cloud-gateway, Service1 and Service2.
Gateway call service1 and service1 calls service2. Service1 and Service2 are using spring web flux
Gateway have 3 filters. global filter, Pre filter and post filter.
spring:
cloud:
gateway:
default-filters:
- name: GlobalFilter
routes:
id: service1
uri: http://localhost:9091/
predicates:
- Path=/service1/**
filters:
- name: PreFilter
- name: PostFilter
In global filter we are reading value from request body setting set as new baggage key.
ExtraFieldPropagation.set(tracer.currentSpan().context() ,X-CUST_TRAN_ID, transactionID);
We have also set Slueth properties like below so that it will be printed in logs as well as forwarded to next services (service1 and service2)
sleuth:
baggage-keys:
- X-CUST_TRAN_ID
log:
slf4j:
whitelisted-mdc-keys:
- X-CUST_TRAN_ID
Problem we are facing is
X-CUST_TRAN_ID values gets send via request and response and printed in service1 and service2's logs but not in Gateway itself.
It does not gets printed either in GlobalFilter's log or in PreFilter log statements but gets printed in PostFilters log statements. Since CUST_TRAN_ID is set in GlobalFilter's filter it should get printed in log statements after set to context.
Please help is there in better way to set the field for propagation as well as printing in log statements.
Sleuth initializes it's context using it's own filter which have a default order. you can try to give an highest precedence of the sleuth filter using the property:
spring:
sleuth:
web:
filter-order: -2147483648
I have a bunch of microservices written using Java and Spring Boot 2.
generation-service, creates an object with a bunch of info and sends it to the next service (in the body of a request pointing to the next service endpoint) that we'll call receiver-service.
Now, I want to test the object generated by generation-service.
Is there any way that I can intercept the request created by generation service and redirect it to a test object? (Spawning a service and pointing generation-service to this endpoint is not an option as I cannot spawn new services.)
Please notice that the post "How to mock RestTemplate in Java Spring?" doesn't solve my problem as I am not interested in testing the response, but the request to the next service. With Rest template I can instead check just the feed that is just OK/FAILED.
I have two endpoints:
CXF_FIRST_ENDPOINT="cxf:bean:cxfEndpoint?{address=first_address}&serviceClass=com.service.class.first"
CXF_SECOND_ENDPOINT="cxf:bean:cxfEndpoint?{address=second_address}&serviceClass=com.service.class.second"
How do I implement two separate web service call after defining the endpoints. If I use both, and consume the endpoints using the routes, one of the endpoints will override the other and I am able to use only one. If I comment the other endpoint, Its running successfully. However I need to use both. I am using messageContentList for both the web service response:
MessageContentsList result = (MessageContentsList) exchange.getIn().getBody();
Thanks, please let me know if you need more information
Here is the route-definition:
from("direct:paymentInfo").routeId("PaymentInfo")
.bean(billingServiceProcessor, "processBillingPaymentRequest")
.to(CXF_BILLINGSERVICE_ENDPOINT)
.bean(billingServiceProcessor, "processBillingPaymentResponse")
.end();
from("direct:Holidays").routeId("HolidayRetrieval")
.bean(entityProcessor, "processHolidaysRequest")
.to(CXF_ENTITYSERVICE_ENDPOINT)
.bean(entityProcessor, "processHolidaysResponse")
.end();
I solved the problem. I found out that both the endpoints were using the same beanid (cxfEndpoint) that was defined in the camel-config.xml.
I defined another id cxfEndpoint1 in camel-config.xml and used it to my endpoint and that solved the problem. Both the web-service calls are working fine without hassles.
<bean id="cxfEndpoint" class="org.apache.camel.component.cxf.CxfEndpoint" />
<bean id="cxfEndpoint1" class="org.apache.camel.component.cxf.CxfEndpoint"/>
and here are the respective endpoints:
CXF_FIRST_ENDPOINT="cxf:bean:cxfEndpoint?{address=first_address}&serviceClass=com.service.class.first"
CXF_SECOND_ENDPOINT="cxf:bean:cxfEndpoint1?{address=second_address}&serviceClass=com.service.class.second"
Thanks,
We have an application which communicates via REST requests made by clients.
The REST requests contain "region name" and a "ID" as parameters
So, a request would look something like this (for a DELETE)
http://host:port/regionnameID
These REST requests between regions in a federation are properly URL encoded
I find that these request fail if the region name has a slash ("/") in it.
Then, the request would look like so
http://host:port/region/nameID
This is due to incorrect interpretation of the Rest URL by HttpRequesthandler when there is a '/' in the region name.
Now, we have no control over clients sending REST request with "/" in the Region name.
Is there any method / configuration / workaround that can be done to prevent the HttpRequestHandler from returning 404
you should rewrite your urls with urlrwrite and use query parameters internal.
<rule>
<name>Inbound:</name>
<from>^(.*)ID$</from>
<to last="true">delete?regionName=$1</to>
</rule>
Add your urlrewrite Filter in front of all other filters in web.xml
This is a bit of a dirty problem. What I would try to do here is to use the Spring #RequestMapping annotation. There is some documentation on it here:
http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html
You can specific ant wildcards in the value you pass #RequestMapping. If you have a limited number of regions, then you can map them all to a single method as follows:
#RequestMapping(value={"/region1**","/region2**","/region3**")
In your controller method, you will have to add additional logical for parsing out the nameID.
If you have a large number of regions, I would then create a separate Spring Web app (servlet) just to handle these requests. That app would have a cached lookup table of regions.
Configure your own handlerMapping bean (perhaps based on AbstractUrlHandlerMapping)