I am preparing for the EJB certification and I am going thro the EJB 3.1 book (O'Reilly)
One of the chapters discusses about JNDI, ENC and the EJB connections
Can some of you give me a real life scenario of these so that I can get a better understandin
JNDI in this scenario is used as a central location through which 'names' (a kind of URL) are routed to an EJB bean. Think of it how a Servlet is mapped to a URL.
If EJB beans are local to an application (e.g. they reside within the web module or within the EJB module of the same EAR), then you don't necessarily need to come into contact with JNDI. Namely, you'd probably use injection to get instances of your bean and no JNDI is needed then.
However, if you need to address an EJB bean in a remote server or if you want to lookup (a proxy to) a bean programmatically, you'd use its JNDI name and JNDI to get hold of it.
See this for some more info, including ENC: Declaring #Resource and #EJB at the class level in Java EE6
Related
I'm new to Camel and bit confused between CamelContext and Registry.
As far as I know that CamelContext is the base object like ApplicationContext in Spring that is used for add routes and maintains the camel life cycle.
Also we got the Registry object from CamelContext but not sure what is the main purpose of this registry.
My intention is to add the component in the context/registry so that JNDIBind can look up the components.
CamelContext: Kind of Camel Runtime that keeps everything in Camel together, e.g.: Endpoints, TypeConverter, Routes, Components and Registry(!).
Registry: allows you to lookup beans, which by default will be JNDI beans. If you use the spring integration it will be Spring's ApplicationContext.
Generally camel when used with spring makes use of the ApplicationContextRegistry to lookup components, endpoints etc with the name of the bean defined in spring-bean.xml file. In places where we need to use JNDIRegistry we would have to add that registry when creating the CamelContext. This is used in places where JNDI objects are shared accross multiple JVMs where JNDI is the best solution.
Please see different types of registry implementation for camel: camel registries
I am developing Spring Web application where many user interact with database cocurrently.i am using SpringJdbcTemplete for communication with database. I have following two beans define.
I only need one Datasource so its defult scope should be Singleton. I have
jdbcTemplate bean autowired to different service class(Admin and user service class).Since my application user can concurrently access this jdbcTempelete instance what should be its defult scope..?
I found that it should be Singleton. But If it is Singleton that only one instance of it will be created and is shared among many requesting user.In this secenerio suppose 1000 user try to access jdbcTemplate at the same time that 999 user have to wait to get it. am iwrong in that if yes please help to avoid my confusion. thanks
As explained in the javadoc of JdbcTemplate the class is thread safe after construction. So as soon as an instance of JdbcTemplate is available it can be shared amongst different threads.
The JdbcTemplate is thread safe and can be used concurrently between multiple threads.
When a bean is thread safe there is nothing preventing you to use a single instance between any number of threads.
More information on using Spring and JDBC Access can be found in the reference guide
Scenario : I'll try to put an analogy with the loan broker example from the EIP book
The customer sends a quote request
(The loan broker requests customer credit score from the credit bureau)
The loan broker sends quote requests to each bank.
The problem
In my case point 1 and 2 are in the same camel context (or osgi bundle)
Each bank has a separate bundle, exposing endpoints to the loan-broker-bundle through NMR
loan-broker-bundle doesn't know about the banks beforehand since we keep partnering with new banks every now and then
What I did
Created a registry class and a bankDescriptor interface in loan-broker-bundle
each bank bundle when started calls the registery to add its bankDescriptor (spring init) that tells the loan broker what endpoint to call to get a quote.
loan-broker-bundle main route uses recipientList (a processor sets target endpoints by asking the registery) to route quote requests
The question
Hoping my description was clear enough, you can see that this is a really simple implementation. What are its limits ? How can i turn this registery into an osgi service ?
I developed a solution like this based on SpringDM for a client. There's a full write up of how to do this at http://www.jakubkorab.net/2012/05/system-integrations-as-plugins-using-camel-and-servicemix.html with full source code available at https://github.com/FuseByExample/smx-application-plugins
Hope that helps.
In OSGi there is a great registry at your disposal: The OSGi service registry. So my proposal is to do this slightly differently. Define a service interface for the quote requests and store it in a api bundle. Then let each bank implement this interface and publish the implementation as an OSGi service.
The loan broker bundle can then list all OSGi services in the OSGi service registry and call each to get the quote. In blueprint there is a nice tag that you can use to inject the list into a bean property of List. Spring DM perhaps has something similar.
Camel currently does not have way to call all OSGi services of a type. We discussed a new osgi service compomnent that would be able to do this. So probably we will soon have a solution.
A registry is a list of items with pointers for where to find the items, like the index on a database table or the card catalog for a library.
Correct me if I am wrong, from this definition, what I'd expect from a camel application registry is where a client application can (depending on the client protocol) do a lookup and based on metadata, selects a particular service and uses it as defined.
I am wondering if Apache Camel has anything close to this. Most of the service registries articles/implementations I have seen seems to address only SOAP protocols.
Regards.
You can use the REST API from camel-web to lookup routes and endpoint which is the "services" in Camel.
http://camel.apache.org/web-console.html
In terms of a SOA service registry then you may look at other products which specialize in that such as Apache ZooKepper
http://hadoop.apache.org/zookeeper/
You can use ManagementStrategy SPI to hook into events in Camel and track services as they are created/started/stopped etc. Then you can bridge that to your SOA service registry product of choice.
you can also use the CamelContext getEndpoints() and getEndpointsMap() APIs to browse the endpoints
see this post for some general monitoring information...
http://benoday.blogspot.com/2011/01/apache-camel-monitoring.html
First of all thanks to folks who are currently involved in the development of Camel, I am grateful for all the hard work they have put in.
I am looking for some design advice.
The architecture is something like this:
I have a bunch of Java classes which when instantiated are required to connect to each other and send messages using Apache Camel. The design constraints require me to create a framework such that all routing information, producers, consumers, endpoints etc should be a part of the camel-context.xml.
An individual should have the capability to modify such a file and completely change the existing route without having the Java code available to him.(The Java code would not be provided, only the compiled Jar would be)
For example in One setup,
Bean A ->Bean B->Bean C->file->email.
in another
Bean B->Bean A->Bean C->ftp->file->email
We have tried various approached, but if the originating bean is not implemented as a Java DSL, the messages rate is very high because camel constantly invokes Bean A in the first example and Bean B in the second(they being the source).
Bean A and Bean B originate messages and are event driven. In case the required event occurs, the beans send out a notification message.
My transformations are very simple and I do not require the power of Java DSL at all.
To summarize, I have the following questions:
1) Considering the above constraints, I do I ensure all routing information, including destination addresses, everything is a part of the camel context file?
2) Are there example I can look at for keeping the routing information completely independent of the java code?
3) How do I ensure Camel does not constantly invoke the originating bean?
4) Does Camel constantly invoke just the originating bean or any bean it sends & messages to irrespective of the position of the bean in the entire messaging queue?
I have run out of options trying various ways to set this up. Any help would be appreciated.
Read about hiding the middleware on the Camel wiki pages. This allows you to let clients use an interface to send/receive messages but totally unaware of Camel (no Camel API used at all).
Even better consider buying the Camel in Action book and read chapter 14 which talks about this.
http://www.manning.com/ibsen/
Save 41% on Manning books: Camel in Action or ActiveMQ in Action. Use code s2941. Expires 6th oct. http://www.manning.com/ibsen/
If you consider using ServiceMix of FuseESB, you might want to separate your routes in two parts.
First part would be the Event-driver bean that trigger the route. It could push messages to the ServiceNMR (see http://camel.apache.org/nmr.html).
The other part would be left to the framework users, using Spring DSL. It would just listen to message on the NMR (push by the other route) and do whatever they want with it.
Of course endpoint definition could be propertized using servicemix configuration service (see http://camel.apache.org/properties.html#Properties-UsingBlueprintpropertyplaceholderwithCamelroutes)