dx帮忙::跨异构平台的分布式事务处理.

03-06-07 bluegirl
小妹初来贵地,还希望各位dx多多指教!

现有一个问题想请教大家:

我的应用服务器WSAD5.0和jboss4.0.0

DBMS:oracle9i和db2.

现在的想实现的功能是websphere中调用一个ejb,实现从oracle中取出100$,然后调用jboss上部署的一个

ejb,实现把100$放到db2中.

这个过程不用RMI/IIOP来做,而是想通过一个分布式事务处理,两阶段提交来完成.

而导师让我用基于jca的理论来做一个适配器来实现.也就是这个适配器要能够实现分布式事务处理.

jboss的专家曾经建议我要在jboss中添加一些jboss的远程框架的mbean,然后实现分布式调用,他的建议如

下:

To propagate the websphere transaction to jboss, you will need to write your own transaction manager

service mbean that provides the websphere transaction manager instead of creating a jboss

transaction manager. You will need to make sure your mbean is installed before you do any jndi

lookups of jboss ejbs. From the client side jboss framework installed when you look up an ejb in jndi,

the TransactionInterceptor and the DTXAResourceInterceptor need to get the transaction manager

from an mbean. For normal clients this mbean is the jboss TransactionManagerService mbean.You

need to make sure there is an mbean server running in websphere, either one that IBM provides or by

using the JBoss one set up by the

org.jboss.system.client.Client class, and install a different

TransactionManagerService mbean that supplies the ibm transaction

manager.Study how remote ejb invocation works. Basically the proxy constructs an Invocation object

which has various context information added to it, and then is sent to the server. There are actually 2

styles of Invocation object: the ejb Invocation gets put into a remoting InvocationRequest object. Your

adapter has to do the same thing. You need to add transaction information and security information.

Look at what the TransactionInterceptor and DTXAResourceInterceptor do, along

with the EjbToRemotingAdapter.

但是我jca开发和jmx,和跨平台分布式事务处理方面没有什么经验,所以请各位dx给小妹出出主意,时间很紧迫.您如果有相似的经验或者是在这方面有些经验,还望不吝赐教!

.谢谢啦!!

banq
2003-06-07 20:37
你要详细分析一下你的应用,Java的东西太多,不能搞太复杂。

我简单说一下,你的应用属于有状态的应用,需要在某地保存一下取出的$100,是美金?这就是有状态。

有状态解决方案有多个:

1. cookie解决,这个方案的好处是J2EE平台可以多个,他们都认识cookie,这是theServerSide.com采取的一个办法

2. Http session, 在分布式环境中,你可以考虑使用同种WEB容器,然后再分别调用不同的EJB容器.

3. statefull session bean,这适合同种EJB容器,不太适合你。

还有可以采取持久化persistence方案,这其中又有多种方案可以选择。

还有JMS,使用JMS来传送的数据,在不同平台间是可以的。

如果你想把架构搞得好看一点,JMS是推荐,如果你想迅速解决问题:

cookie和Http session值得一试验。

至于使用JCA,我个人认为对于你这个应用是大炮轰蚊子,如果你有一套EAI,花精力去做JCA是值得,否则,象这样深入平台的工作少做,因为你以前是在用J2EE平台容器(就是用也够麻烦的),你现在则要去学会平台容器的制造原理(头能不大吗?)

Jevang
2003-06-08 11:25
Hi Dx,

You have picked a very interesting topic, though I can't see much value of it in real world and I don't have an answer for it, but it's good for brain exercise.

I think the key to your problem is XA, you need a single, distributed transaction across heterogenous systems. first let's take a look how you do the same action in a single/homogenous system.

you need call two ejbs from client, ejb does not need to be stateful but they must be in same transaction context. use UserTransaction and controlled it from client, that's no brainer. agree?

Now you want the second ejb lives in different system, the transaction manager from second one defintely need be attached or delegate control to first(primary) one. The suggestion you got from that expert basically is let jboss become another managed resource of websphere, so you pass the transaction context in second ejb call become recognized as it's still managed by same transaction manager.

Communicate with MBean remotely thru RMI is trivial once you figure out how to write that mbean, I believe you just have to dig into the websphere integration doc as any vendor who want to integrated with it would do the same thing. e.g Sonic MQ to websphere.

JCA maybe a wrong term here as it already carry a well known meaning, but you do need a implementation in similar pattern to work with another external resource, except it's being managed instead of managing position.

Now go back to the original point of usefulness, I never seen people want to get into trouble of scenario that you are pursuing, ( it's nice to stay in school ;-) )I do see people need to contact another app server from one server, actually I have done transaction routing myself but that's more like a nested/chain mode transaction usage, think about calling third party jms from ejb is a case as well.

Even you manage to make the simply case work as wanted,what happen when you do more things? let's assume you need to send a message(of course, within same tran), thought tran context maybe propogated thru threadlocal, but how can you sure the connection you get from JMS will be associated with that "remote" transaction manager? it may have problem even with XA jdbc connection, of course, this whole depends on jboss implementation.

You are using jboss 4 ? good luck. recently I can't resist the temptation to try out joss3.21, guess what, my topas server broken in many places, it took me almost a half day to figure out the places that's not compatible.

Brain machine is slowing down, so stop here.

$0.02

-Jevang

bluegirl
2003-06-09 09:00
谢谢二位仁兄的指教:

说实话,我现在还是一名学生,在公司实习,因为实习期要到了,而这个困扰我的问题还没有得到解决.或者像您说的,现在还没有一个清晰的思路:(

看来用JCA是不必要了,通过查资料,我也是这么认为,可是导师的意思是让我用jca原理做一个adapter,实现连接.

如果不用jca的话,那像您说的用jms应该如何来做?如何保证数据的一致和正确性呢?也是进行二阶段提交吗?那还要不要用到Mbean?

能提供一下这方面的资料或者例子吗?在线等待!

谢谢!

Jevang
2003-06-09 09:22
JMS is the not solution to your problem, it's simply a reliable way to convey data, in your case a simple ejb call will do the same thing. If I understand you correctly, you need a 2pc on top of was and jboss. you can deliver a msg in transaction mode but the jms server in jboss still use its own TX manager.

bluegirl
2003-06-09 09:54
谢谢!这么快就有回复!

在wsad和jboss之上?那是要另外一个应用服务器吗?

可以在wsad或者是jboss中启动全局事务吧?现在可以实现两个jboss之间二阶段提交的分布式事务处理,关键就是如何实现jboss和wsad之间的分布式的问题.

Jevang
2003-06-09 10:26
you get the point now, but I don't think this is available today. you have to get familiar with JTS in jboss.

Does not mean to scorn the people here, but I think you can get better answer if you post the question to some cotainer oriented forums. For chinese site, you can try huihoo group or maybe this guy hidebrain@sohu.com.

-Jevang

bluegirl
2003-06-09 11:05
Oh!但是jboss没有提供异构平台之间分布式的事务的处理.

如果在wsad中使用jms来调用jboss中的ejb,是不是不能保证数据的一致性?

Jevang
2003-06-09 11:39
As I said before, jms is not the solution, actually using it may requires you may effort. the ejb in jboss is going to use some XA resources, mostly jdbc connection, it could be a jms connection as well( this has nothing to do with passing your transaction or data between two app servers), you need let me under control of was tx mgr.

-Jevang

banq
2003-06-09 13:34
其实比较可行的解决方案是在WEB端,分别访问两个J2EE容器。

关于transaction是另外的问题,这其实就象在讨论web service一样,web service的transaction是另外一个课题,我们目前解决的是在分布式环境中这两种J2EE容器的无缝融合问题。

分布式系统中,往往WEB容器和EJB容器是分布在不同服务器之间的,在WEB中实现访问不同的EJB容器是很容易实现的。

在分布式环境中,JMS可能不是最快的,但是是最有效率的,其实在分布式中,我们考虑的第一因素已经不是性能,最快,而是效率问题,要让每台服务器都在满负荷运行,不能有闲有空,因此,在这样环境中,必然会存在JMS。

那么 使用JMS解决你的问题就是顺其自然的事情,我不赞成在分布式环境中引入太多框架,因为目前而言,EJB和JMS是分布式系统比较成熟可行的技术框架。

至于如何解决你的问题,详细一点如下:producer方在你的webshere端,它会通过JNDI查找connectionFactory,你要设置你的JNDI,将这个ConnectionFactory导向你的Jboss server, consumer在你jboss方,是个MDB,在MDB中你进行EJB操作,至于结果如何走,是再一次JMS,还是其他方法,取决于你的应用的上下文。

你的导师让你用JCA,可能是让你学习JCA,JCA和分布式环境是两个不相关概念,JCA通过JMX的一个组件,JMX 实现分布式架构的标准刚刚出现。

有些人过分看中JCA的用途,因为是它的名字connector adapter,以为是个万能的连接器框架。

bluegirl
2003-06-09 16:14
谢谢板桥x!

websphere和jboss互联可以使用iiop.只要指出jboss上的ejb所在的ip地址和用jndi指出这个ejb即可.可以实现调用.

或者是如果用jms,那就像您说的在websphere中启动一个消息服务JMS,JBoss设计一个消息驱动Bean作为命令接收者,接收到以后调用JBoss中的Ejb.也可以实现调用,而这个JMS的启动也是靠jboss所在的ip和消息驱动bean的jndi来找到的吧?

那么这两种主要是能不能实现两阶段提交?

给我感觉他们两个各自的事务还是独立的.

没有使用一个全局id来动态的完成一个分布式事务.

我说的可能不对,希望指教!

banq
2003-06-09 16:53
在 EJB设计模式中有个MDB facade, 如图:

MDB facade类似session facade, 可以将一系列事务操作交给一个JMS Queue去完成。

MDB facade的好处是防止单点错误风险,在其中访问的EJB或数据库发生问题时,JMS的事务机制将发挥作用,将这些未完成的数据保存在queue中,等待EJB或数据库恢复正常,将再次进行操作。

你可以看看这个英文原版书,在本站设计模式中有。

blues
2003-06-09 17:35
hello,banq;

在你贴出的示例图中,jms队列的消费者还是部署在一个container中的部件。dx提出来的问题是如果还有一个异构的container,怎么让这2个container中的部件加入到一个transaction中。

在早些时候我提了一个问题是如何让几个web service加入到一个transaction中,似乎和dx所提的问题性质一样。

banq
2003-06-09 17:49
有两种解决方案。

1. 这个过程起点交给JMS做,由JMS负责调用不同容器的EJB完成,事务机制由JMS实现。

2. 起点由WASD的EJB先完成自己的操作,然后操作JMS,通过JMS操作Jboss。

3. 起点由WASD的JMS,WASD的JMS再驱动Jboss的JMS,这是一个JMS链。这样一个过程也是保持事务安全的。

Jevang
2003-06-09 23:16
To Banq,

I think we are talking about ACID here based on the title and previous reply from "bluegirl". hi, be careful when you do account transferring. ;-(

To Blues,

are you bluegirl's brother/sister? Just kidding. I think you are right one the point about single/homogeneous container vs. multiple container. Regarding your question about transaction control across webservice calls, I think in theory it is feasible but probably no implementation yet and it's against the common usage of web service: normally web service is high level abstraction func, it is used in stateless fashion.

Cheers

-Wanchun

猜你喜欢
4Go 1 2 3 4 下一页