MDB做Facade的几个疑惑
用MDB和SLSB组合来做facade的好处这里就没必要说了,但是现在在具体用MDB来做facade的时候就碰到一些问题:
1、客户端只能针对某个Queue和Topic和发送Message,而MDB在onMessage()调用具体的逻辑代码。客户端基本上是针对一个用例发送一个Message,所以要么就是几个用例发送到一个Queue或者Topic,然后在MDB里做判断再调用具体逻辑代码。这样子MDB里就充斥了一堆 if.... else if....,日后维护起来也很郁闷;
要么就是针对用例建立不同的Queue或者Topic,然后客户端选择不同的目的进行发送Message,但是这样就会有一堆的Queue和Topic,而且还有相应的MDB,数量恐怕不会少,恐怕到多的时候连自己都会糊涂了。
不知道针对这个问题大家是怎么解决的。
2、在EJB CookBook里有提到:
When a transaction in a message-driven bean rolls back, the application server
can be configured to resend the JMS message that started the transaction. If the
error that caused the rollback keeps occurring, you could potentially cause an
endless loop.
他的解决办法是:
private HashMap previousMessages;
private int count = 0;
public void onMessage( Message incomingMsg )
{
// get the unique message Id
String msgId = incomingMsg.getJMSMessageID();
if ( previousMessages.containsKey(msgId) )
count = ( (Integer) msgMap.get(msgId) ).intValue();
else
count = 0;
// if msg has been retried couple of times, discard it.
// and remove the stored id.
if ( count < _MAX_REDLIVERY_CONST_ )
{
logMessage(incomingMsg);
previousMessages.remove( msgId );
return;
}
//perform business logic for message
boolean error = doBusinessFunction();
if ( error )
{
mdbContext.setRollBackOnly();
previousMessages.put( msgId, new Integer(++count) );
}
else
{
if( previousMessages.containsKey( msgId ) )
previousMessages.remove( msgId );
}
}
我认为这么做是不是只能对对Queue只有一个MDB接收实例的时候能起作用,也就是所pool不能多于一个,书上也有提到可以用服务器特定的描述符设定来实现,不知道weblogic是怎么设定的,我没找到
^^!!!
3、怎么防止未授权的用户发送Message或者说是过滤相应的Message
我知道对于后者可以设定:
<message-selector>
<![CDATA[ UserRole = 'BuyerRole' ]]>
</message-selector>
我觉得这样还不够,不知道还有没有什么其他的方法
请各位大虾出手,解答小弟心中的疑惑,谢谢!!
不知道还有没有其他的解决方案或者类似的东西可以参考,希望大家多多帮忙