MDB 通过数据源连接到 Oracle AQ
我正在尝试创建一个连接到 Oracle AD 队列的 MDB (JBoss AS 6)。
我得到了以下示例:
@MessageDriven(name = "TestMdb", activationConfig = {
@ActivationConfigProperty(propertyName="destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName="connectionFactoryProperties", propertyValue="jdbc_connect_string=jdbc:oracle:thin:XXXXX@XXX:1521:XXX,host=XXXX,user=XXXX,password=XXXX,port=XXXX,sid=XXXX,driver=XXXX"),
@ActivationConfigProperty(propertyName="destinationProperties", propertyValue="owner=XXXXX,name=jms_text_que"),
@ActivationConfigProperty(propertyName="userName", propertyValue="XXXX"),
@ActivationConfigProperty(propertyName="password", propertyValue="XXXX"),
@ActivationConfigProperty(propertyName="ConnectionFactoryClassName", propertyValue="oracle.jms.AQjmsConnectionFactory"),
@ActivationConfigProperty(propertyName="QueueConnectionFactoryClassName", propertyValue="oracle.jms.AQjmsQueueConnectionFactory")
})
@ResourceAdapter("XXXXXX-ear.ear#genericjmsra.rar")
@TransactionManagement(TransactionManagementType.BEAN)
public class TestMdb implements MessageListener {
public void onMessage(Message message) {
...
}
}
问题是我需要直接在代码中指定连接属性(包括数据库主机、用户名和密码)。 有谁知道如何使用 jndi 查找中的数据源?
谢谢
Im trying to create a MDB (JBoss AS 6) that connect to an Oracle AD queue.
I got the following example to work:
@MessageDriven(name = "TestMdb", activationConfig = {
@ActivationConfigProperty(propertyName="destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName="connectionFactoryProperties", propertyValue="jdbc_connect_string=jdbc:oracle:thin:XXXXX@XXX:1521:XXX,host=XXXX,user=XXXX,password=XXXX,port=XXXX,sid=XXXX,driver=XXXX"),
@ActivationConfigProperty(propertyName="destinationProperties", propertyValue="owner=XXXXX,name=jms_text_que"),
@ActivationConfigProperty(propertyName="userName", propertyValue="XXXX"),
@ActivationConfigProperty(propertyName="password", propertyValue="XXXX"),
@ActivationConfigProperty(propertyName="ConnectionFactoryClassName", propertyValue="oracle.jms.AQjmsConnectionFactory"),
@ActivationConfigProperty(propertyName="QueueConnectionFactoryClassName", propertyValue="oracle.jms.AQjmsQueueConnectionFactory")
})
@ResourceAdapter("XXXXXX-ear.ear#genericjmsra.rar")
@TransactionManagement(TransactionManagementType.BEAN)
public class TestMdb implements MessageListener {
public void onMessage(Message message) {
...
}
}
The problem is that I need to specify the connection properties directly in the code (including DB host, username and password).
Does anyone know a way to use a datasource from a jndi lookup?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令人恼火的是,MDB 注释配置的教科书实现规定了环境和安全特定值的硬编码。 Java 中的注释处理也非常聪明,可以确保您不会偷偷输入一些非常量值,例如 final String MyConfig = System.getProperty(....)。
无论如何,您可以将部分或全部 MDB 配置配置为 XML 部署描述符,这更友好一些(尽管构建和部署稍微复杂一些)。 JBoss XML 部署描述符可以在引用系统属性的 ${} 令牌中分配值,因此从配置角度来看它们更易于管理。
It is infuriating that the textbook implementation of MDB annotation configuration dictates the hard coding of environment and security specific values. Annotation processing in Java is also devilishly clever about making sure you are not sneaking in some non-constant value like a final String MyConfig = System.getProperty(....).
At any rate, you can configure some or all of the MDB configuration to an XML deployment descriptor which is a bit more friendly (although a bit more complex to build and deploy). JBoss XML deployment descriptors can have values assigned in ${} tokens that reference system properties so they're a bit more manageable from a configuration perspective.