什么是JCA container?

CaOding 2006-05-05 11:28:44
可否详细精炼地介绍一下?谢谢呀!!~
...全文
290 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
YuLimin 2006-12-03
  • 打赏
  • 举报
回复
JCA(Java Connector Architecture) 提供了一个应用服务器和企业信息系统连接的标准Java解决方案,以及把这些系统整合起来实现最好的工作效率的方法。

JCA(J2EE Connector Architecture)是J2EE体系架构的一部分,为开发人员提供了一套连接各种企业信息系统(EIS,包括ERP、SCM、CRM等)的体系架构,对于EIS开发商而言,它们只需要开发一套基于JCA的EIS连接适配器,开发人员就能够在任何的J2EE应用服务器中连接并使用它。基于JCA的连接适配器的实现,需要涉及J2EE中的事务管理、安全管理及连接管理等服务组件。
MuseIn 2006-05-06
  • 打赏
  • 举报
回复
The JCA Java Connector Architecture provides the most efficient way of thread pooling, resource pooling, transaction handling and consumption on JMS and other Resource Adapters. For example if you are consuming JMS messages, the JCA container provides the most efficient way of pooling the JMS sessions and connections, pooling threads and processing messages in parallel as well as transaction and exception handling.

The following are the steps to configure a Message Driven POJO in Spring with Jencks. There is the complete XML here

Configure the JCA Container
Just add the following to your Spring configuration file

<bean id="jencks" class="org.jencks.JCAContainer">

<!-- lets use the default configuration of work manager and transaction manager-->
<property name="bootstrapContext">
<bean class="org.jencks.factory.BootstrapContextFactoryBean">
<property name="threadPoolSize" value="25"/>
</bean>
</property>


<!-- the JCA Resource Adapter -->
<property name="resourceAdapter">
<bean id="activeMQResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter">
<property name="serverUrl" value="tcp://localhost:51616"/>
</bean>
</property>
</bean>
Which will create the JCA container.

Notice that the bootstrapContext property is used to create the JCA BootstrapContext which includes the WorkManager (which is the JCA ThreadPool). This allows you to configure the thread pool size, transaction manager and so forth.

Notice that there is a work manager you can configure to set the thread pooling limits.

Also you can associate whichever JCA Resource Adapter you wish, such as to use another JMS provider. If you have a modern JMS like ActiveMQ it will come with its own optimised Resource Adapter. If your JMS provider does not have its own RA then consider using the GenericRA

Consuming inbound JMS messages
The following shows an example:

<bean id="inboundConnectorA" class="org.jencks.JCAConnector">

<property name="jcaContainer" ref="jencks" />

<!-- subscription details -->
<property name="activationSpec">
<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
<property name="destination" value="test.spring.inboundConnectorA"/>
<property name="destinationType" value="javax.jms.Topic"/>
</bean>
</property>

<property name="ref" value="echoBean"/>
</bean>

<bean id="echoBean" class="org.jencks.TestBean" singleton="true"/>
The activation specification is dependent on the JCA Resource Adapter being used. If you are using ActiveMQ as your resource adapter then here are all the various properties you can configure, giving you full control over every aspect of the JMS subscription, pooling and delivery mode.

The POJO which implements the JMS MessageListener interface is referenced via the ref property in the inbound connector. The echoBean in this example can be any POJO created by Spring. If you wish you can use a spring singleton, or can add your own Spring interceptors around it - though note that Jencks already takes care of security and transaction handling for you automatically.

If you are using XA transactions on inbound messages and want to support recovery (that is on start up any in-progress transactions are recovered) then you must specify an id or name in the Spring XML configuration for the inbound connector as shown above. Failing to do so with a transaction manager such as Geronimo's will result in an exception during recovery.


Configuring the concurrency of message processing
One of the main points of using JCA is to allow you to process inbound messages concurrently in a thread pool using a pool of JMS connections and sessions. There are 2 main configuration points you can use in Jencks

the thread pool size defines the maximum number of concurrent messages that can be processed in Jencks across any subscription in that JCAContainer.
for some ActivationSpec implementations you can further configure the subscription to define the concurrency model. For example in ActiveMQ you can specify the maxSessions and maxMessagesPerSessions properties to configure how many concurrent messages can be processed for that subscription.
Using both approaches you can define how many threads are used for all the subscriptions and also how many of those threads can be used up by each subscription. This means you can segment your subscriptions to ensure one subscription doesn't overload other subscriptions.

You can also create multiple JCAContainer instances to allow you to have completely separate thread pools for different kinds of subscriptions if you wish.

Avoiding coupling your code to the JMS API
If you would rather avoid using the JMS MessageListener interface altogether you could use Spring Remoting with Jencks using the Lingo library.

Lingo is an implementation of Spring Remoting which adds remoting onto any POJO model. Lingo then takes care of all of the JMS code on both the client side and server side for you; marshalling things into and out of JMS Messages for you.

See the Lingo JCA example

Using XA
To use XA for an inbound connection in the JCA container you'll need to specify a transaction manager to the inbound connector. Here's an example

<bean id="inboundConnectorA" class="org.jencks.JCAConnector">

<property name="jcaContainer" ref="jencks" />

<!-- subscription details -->
<property name="activationSpec">
<bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
<property name="destination" value="test.spring.inboundConnectorA"/>
<property name="destinationType" value="javax.jms.Topic"/>
</bean>
</property>

<!-- use XA transactions -->
<property name="transactionManager" ref="userTransaction"/>

<property name="ref" value="echoBean"/>
</bean>
You also need to provide a transaction manager implementation to use. Here this exampe uses Geronimo.

<bean id="transactionContextManager" class="org.jencks.factory.TransactionContextManagerFactoryBean"/>
<bean id="userTransaction" class="org.jencks.factory.GeronimoTransactionManagerFactoryBean"/>
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction" ref="userTransaction" />
</bean>
Sending outbound JMS messages
Jencks also supports JCA pooling and transaction support for Outbound JMS

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧