camel not knowing amount of endpoints in loadbalancer - apache-camel

Is it possible to loadbalance in a camel route without knowing the amount of endpoints before runtime?
As an example, certain incoming requests has to loadbalance over certain servers and the servers are configured.
using .loadBalance().failover().to() how can I dynamically set the amount of to() endpoints?
I have tried it with toD() and sending a string of comma seperated endpoints but it sends the request to all servers and does not loadbalance.

To do this, you'll need to use the Java DSL.
//Setup dynamic list of endpoints
List<String> toDefs = new ArrayList<String>();
toDefs.add("mock:a");
toDefs.add("mock:b");
//We need to modify the definition, so get the reference
LoadBalanceDefinition loadBalanceDefinition =
from("dirct:start")
.loadBalance()
.failover();
//Dynamically add the list of endpoints
for (String toDef: toDefs){
loadBalanceDefinition = loadBalanceDefinition.to(toDef);
}
//Finalize the route
loadBalanceDefinition.to("direct:end");

Related

How to query Solr for a Collection's details, such as a Collections' config name?

How can I query Solr, using the HTTP API, for information about a collection? I'm not talking about the collection's indexes, which I could query using the COLSTATUS command. I'm just talking about the basic details of a collection, which you can see when you click on a collection in the Solr web admin page, such as config name.
When wondering where information provided in the web interface comes from, the easiest way is to bring up your browser's development tools and go to the Network section. Since the interface is a small Javascript application, it uses the available REST API in the background - the same that you'd query yourself.
Extensive collection information can be retrieved by querying:
/solr/admin/collections?action=CLUSTERSTATUS&wt=json
(Any _ parameter is just present for cache busting).
This will return a list of all the collections present and their metadata, such as which config set they use and what shards the collection consists of. This is the same API endpoint that the web interface uses.
collections":{
"aaaaa":{
"pullReplicas":"0",
"replicationFactor":"1",
"shards":{"shard1":{
"range":"80000000-7fffffff",
"state":"active",
"replicas":{"core_node2":{
"core":"aaaaa_shard1_replica_n1",
"base_url":"http://...:8983/solr",
"node_name":"...:8983_solr",
"state":"down",
"type":"NRT",
"force_set_state":"false",
"leader":"true"}}}},
"router":{"name":"compositeId"},
"maxShardsPerNode":"1",
"autoAddReplicas":"false",
"nrtReplicas":"1",
"tlogReplicas":"0",
"znodeVersion":7,
"configName":"_default"},
...
}
Please try the below code.
getConfigName(String collectionName){
//provide the list of zookeeper instances
List<String> zkHosts = ""
// get the solr cloud client
CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder (zkHosts, Optional.empty
()).build ();
// get the config for the collection
String configName = solrConnectionProvider.getCloudSolrClient().getZkStateReader().readConfigName(collectionName);
return configName;
}
Please handle the exception(s) from your end.

Validate AppEngine Endpoints Client IDs while using custom Authenticator

Earlier our client side apps used Google Sign-In.
Now we are moving to custom auth, as we plan on having the user's phone number as the only identity (instead of a Google Account). But after implementing the custom Authenticator, the client IDs are not being checked and I am able to make API calls from anywhere.
When only Google Sign-in was being used at the client side, the client ID was being validated and I was not able to make API calls from any clients other than the ones authorized.
How do I verify the Client IDs while using custom authenticator?
Code for the Api Endpoint
#Api(name = "apiSubscriber",
clientIds = {
Constants.webClientId,
Constants.androidClientId,
Constants.iOSClientId
},
authenticators = {com.google.api.server.spi.auth.EndpointsAuthenticator.class,
CustomAuth.class},
audiences = {Constants.androidAudience},
)
public class ApiSubscriber {
#ApiMethod
public Subscriber getSubscriberData(User user){
if(user!=null){
//fetches subscriber data
}
}
//... Other ApiMethods
}
Code for Custom Authenticator
public class CustomAuth implements Authenticator {
#Override
public User authenticate(HttpServletRequest request) {
String phoneNumber = request.getHeader("phoneNumber");
String token = request.getHeader("Authorization");
if(checkToken(phoneNumber,token)){
return new User(phoneNumber);
}
return null;
}
private boolean checkToken(String phoneNumber, String token){
//Checks if authorization token is valid
}
}
Unfortunately at this time, it does not appear that you can restrict your Endpoints API to a client and not use Google Sign in.
When using Google's oAuth2 authentication some magic voodoo happens (not exactly sure what) and apps get restricted to the ClientId's that you specify.
However, when you stop using that authentication method, I have found (to my dear disappointment), that it does not work anymore.
See my question here where you can read about my tests and some additional things that may give you more information: Authenticating your client to Cloud Endpoints without a Google Account login
I don't sure is it a problem, but you have some bugs in code you provided.
authenticators = {com.google.api.server.spi.auth.EndpointsAuthenticator.class,
CustomAuth.class,
instead of comma must be bracket. Also, imho, you need only CustomAuth class here.
audiences = {Constants.androidAudience},
comma is redundant.
Second. You don't required to use custom Authenticator. You can send token and phone number as concatenated parameter or two parameters to your service method and check it there.

How to store and load the connections of jsplumb (Using AngularJS and jsPlumb)

Can pls anyone help me out how to store and load the connections, and anchor placements jsplumb and anjular js.
pls check the below image link
(http://i.stack.imgur.com/YC1PR.jpg).
1st one is the image without connections, second one with connections.
when i reload the page, still i need to get the connections in same places
Whenever a connection is established, "connection"(SOURCE) event is triggered. You need to store the connection endpoints details in that triggered function so that you can retrieve them later.
First make sure that you have set proper id for your endpoints. You can manually set at time of endpoint creation as:
var e0 = jsPlumb.addEndpoint("div1",{uuid:"div1_ep1"}), // You can also set uuid based on element it is placed on
e1 = jsPlumb.addEndpoint("div2",{uuid:"div2_ep1"});
Now bind the connection event where you will store the established connections info:
var uuid, index=0; // Array to store the endpoint sets.
jsPlumb.bind("connection", function(ci) {
var eps = ci.connection.endpoints;
console.log(eps[0].getUuid() +"->"+ eps[1].getUuid()); // store this information in 2d-Array or any other format you wish
uuid[index][0]=eps[0].getUuid(); // source endpoint id
uuid[index++][1]=eps[1].getUuid(); // target endpoint id
}
});
You can convert the array information to JSON format and store at the server side. When page is refreshed you need to retrieve the JSON data and restore the connection. For connecting the endpoints based on uuid make use of:
jsPlumb.connect({ uuids:["div1_ep1","div2_ep1"] });
Here is the jsFiddle for making connections based on endpoints.

How to take param values from Task Queue url.?

Queue queue = QueueFactory.getDefaultQueue();
queue.add(("/worker").param("key", "ABC"));
how to take key value .? using below code or any other approach.
request.getParameter("key");
Absolutely. The /worker endpoint is configured in your web.xml as a Servlet. The request object will be passed to your Servlet method and you can use the standard methods like the one you have specified i.e. getParameter(...)

Using CloudSolrServer as SolrJ client

My question is when we are using CloudSolrServer, we specify single zkHost address and LBHttpSolrServer. Now CloudSolrServer does extracts information about alive and dead nodes from zookeeper (zkHost) and serves the requests.
But what if the zkHost specified as argument it self goes down ? I think CloudSolrServer should accept more then one zkHost, as the case with LBHttpSolrServer, which accepts more then one solr server urls.
Any idea ?
Thanks
According to this: http://comments.gmane.org/gmane.comp.jakarta.lucene.solr.user/71075
You can pass a comma-delimited list of Zk addresses in your ensemble, such as:
zk1:2181,zk2:2181,zk3:2181, etc.

Resources