Creating routes on Camel using domains - java

I'm running an instance of Apache Camel in order to proxy requests to another server (depending on the URI). The server Camel is running responds through a lot of a different domains (e.g. app1.server.com, app2.server.com).
By using jetty and http4, I was able to proxy requests by doing this:
from("jetty://http://app.server.com:8080/app1?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
from("jetty://http://app.server.com:8080/app2?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
Is there any way which is possible to create routes according to the domain name? Something like this:
from("jetty://http://app1.server.com:8080?matchOnUriPrefix=true").to("http4://app1host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
from("jetty://http://app2.server.com:8080?matchOnUriPrefix=true").to("http4://app2host:8080?bridgeEndpoint=true&throwExceptionOnFailure=false");
Thank you very much.

You could create Content Based Router (http://camel.apache.org/content-based-router.html) like this
from("jetty://http://0.0.0.0:8080")
.choice()
.when(header("host").contains("app1.server.com"))
.log("app1.server.com").to(...)
.when(header("host").contains("app2.server.com"))
.log("app2.server.com").to(...);

Related

Apache camel don´t use all the dynamic queues created

I'm using apache camel for consuming an IBM Mq, I use jms for that, everything is ok that works fine, but in the performance testing the api create a lot of dynamic queues but just use once, I've used a lot of properties for solve this problem but I didn't get it yet. my api use a pattern InOut so the responses are in queue in a dynamic queue, when exist a lot of them, for example my api create 50 dynamic queues, but just use 3 of them.
Here are the properties I used to solve it, but didn´t work for me:
-maxConcurrentConsumers
-conccurrentConsumers
-threads
I found a solution for this and is this.
this is my consume to mq
.setHeader("CamelJmsDestinationName",
constant("queue:///"+queue+"?targetClient=1"))
.to("jms://queue:" + queue
+"?exchangePattern=InOut"
+"&replyToType=Temporary"
+"&requestTimeout=10s"
+"&useMessageIDAsCorrelationID=true"
+"&replyToConcurrentConsumers=40"
+"&replyToMaxConcurrentConsumers=90"
+"&cacheLevelName=CACHE_CONSUMER")
.id("idJms")
and this is the properties to connect the mq
ibm.mq.queueManager=${MQ_QUEUE_MANAGER}
ibm.mq.channel=${MQ_CHANNEL}
ibm.mq.connName=${MQ_HOST_NAME}
ibm.mq.user=${MQ_USER_NAME}
ibm.mq.additionalProperties.WMQ_SHARE_CONV_ALLOWED_YES=${MQ_SHARECNV}
ibm.mq.defaultReconnect=${MQ_RECONNECT}
# Config SSL
ibm.mq.ssl-f-i-p-s-required=false
ibm.mq.user-authentication-m-q-c-s-p=${MQ_AUTHENTICATION_MQCSP:false}
ibm.mq.tempModel=MQMODEL
the issue was in the MQ Model, the MQModel has to be shared if you are using the pattern inOut, this is because the concurrent create dynamic queues using the mqModel

Different ports on spring actuator

We have following spring setup:
Our application is running on port 80, but our managment.server.port is set to 8081. And we use multiple checks of the management endpoints from this secured port already.
server.port=80
management.server.port=8081
management.endpoints.web.exposure.include=*
With this settings we can hide any sensitive information from the public interface on port 80.
But now our requirements changed: We need to display the version of our application on the public interface. This information is part of the info-endpoint of our management-server on /actuator/info
Is it possible to move only the info endpoint to port 80, and let all other management.server endpoints still on 8081?
Or is there any other suitable solution for our requirement to only open the info endpoint for external calls.
We prefer to not change any firewall setting: so one port is public, and the other is internal only
No you can't move only one endpoint to different port.
This about the actuator as an application that runs on one specific port (8081) in this case and exposes a bunch of services, so its all-or-nothing from this standpoint.
So you'll have to create a special rest controller that would read the file (or keep the memory) the data just like the info endpoint does.
Its a pretty staightforward code actually, it reads a file available in the spring boot artifact anyway and exposes its content.
You can checkout the source code of the info endpoint of the actuator here

Create multiple Ribbon clients dynamically

I have a spring microservices architecture application but we aren't using eureka or any other service discovery. My requirement is to create a dynamic load balancer. So, for each services there will be unique and dynamic set of servers.
The configuration will be something like:
ribbon:
listOfServices: say-hello-service, say-hi-service
What I don't want to do is, repeat #RibbonClient annotation for each service client that I will use.
I found out that RibbonClientSpecification is the key component of the Ribbon factory. If I register it with names say-hello-service.RibbonClientSpecification and say-hi-service.RibbonClientSpecification, it will try to call respective service even though I don't have #RibbonClient and any Ribbon related configuration. So my questions are
Why is #RibbonClient annotation necessary since we can identify the services from the properties defined? It seems to me that, it is redundant what we have to define ribbon properties in properties file and as well as have the annotation with same name.
How do I register load balancers for each ribbon client that I create dynamically?
What is the right of creating multiple ribbon clients dynamically without having multiple #RibbonClient configuration classes?
You can use its as
#RibbonClient("{services1,service2}")
No need to specify or create new ribbon all the time for different service.

Match Multiple URL Paths with Apache Camel CXF Endpoint

We are using Apache Camel with CXF endpoints to process our web service requests. What I'd like to be able to do is have my application be able to accept messages on any URL like:
http://localhost:9000/[anything]/MyService
http://localhost:9000/foo/MyService
http://localhost:9000/bar/MyService
I think I could make this a configurable setting, but I would much rather have it be completely dynamic and accept any path component before my service name. I've read about the Camel URL Rewrite Component and it seems like that may work, but it didn't feel like the right answer.
If it helps here is my endpoint configuration (with some details removed for brevity):
<cxf:cxfEndpoint id="MessageEndpoint"
serviceClass="MyClass"
serviceName="RespondingGateway_PortType"
address="{{web-service-url}}:{{port}}/subpath/MyService">
</cxf:cxfEndpoint>
What I'd like to be able to do is put something like /*/subpath/MyService in the address property to match on anything, but this doesn't work.

Humanizing the URL scheme when deploying a Spring app to a production environment

I am a complete newbie, just starting with Spring.
I have developed a sample app which I want to deploy on a production environment. My problem is that my app serivces still look like that:
http://mydomain.com:8400/myserver/myapp/controller/view
I want to humanize this and turn it into something like that:
http://mydomain.com/controller/view
basically removing the port as well as the boilereplate /myserver/myapp/, since this domain will be used entirely for the purposes of that app
However, I still want to keep the existing url scheme as well.
How do I do that? do I have to configure server.xml (for the port), web.xml, .htaccess or something else?
To remove the port, you have at least 3 choices:
let the container server (Tomcat or what ever) run on port 80
use a Proxy Server (for example Apache Httpd) run on port 80 and forward the requests to your application Server (Tomcat)
use some Firewall constraints to forward the requests fron port 80 to 8080
To get rid of the log path: you can use a combination of that ideas:
(if you use an tomcat) rename the war to ROOT.war (uppercase) instead of myapp.war. Then you will get rid of the "myapp" part.
Use some java framework like tuckey UrlRewriteFilter to change the rest of the urls

Categories

Resources