从PL / SQL调用/使用JMS [英] Calling/Using JMS from PL/SQL

查看:212
本文介绍了从PL / SQL调用/使用JMS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从PL / SQL调用/使用JAVA消息服务(JMS)?

Is it possible to call/use JAVA Messaging Service (JMS) from PL/SQL?

我知道我们可以从pl / SQL调用java,但是调用java与调用JMS队列或JMS主题不同,因为JMS依赖于JNDI资源命名,当我们使用基于JNDI的资源时,我们首先必须将它们部署在某个J2EE容器中然后使用它们。所以调用JMS总是涉及在某个J2EE容器上部署然后利用它的功能。

I know we can call java from pl/SQL, but calling java is different from calling JMS Queues or JMS Topics, because JMS depends upon JNDI-resource naming and when we use JNDI based resources we first have to deploy them in some J2EE container and then use them. So calling JMS always involves deploying on some J2EE container and then utilizing its functionalities.

回到我之前提到的问题,我想使用PL / SQL中的JMS以及如何处理部署和基于JNDI的资源...?

Coming back to my question as i mentioned earlier, i want to use JMS from PL/SQL and how it would handle the deployment & JNDI-based resources stuff..?

推荐答案

您的问题中有两个问题需要单独解决:

There are two issues in your question that need to be addressed separately:

不,调用JMS服务不依赖于拥有JNDI资源,也不需要拥有JMS客户端部署在容器中。在容器中使用JNDI的原因是为了避免在应用程序代码中使用硬编码的配置参数(通过使用名为things的目录。)

No, calling a JMS service does not depend on having a JNDI-resource nor you need to have the JMS client deployed in a container. The reason for using JNDI within a container is to avoid having configuration parameters hard-coded in your application code (by using a "directory" of named "things".)

例如,我们使用JNDI来获取连接池,从中获取jdbc连接,但我可以直接创建一个jdbc连接。后者适用于测试或命令行实用程序,但对于一般情况肯定不合适(这就是为什么我们通常选择以前的基于jndi的选项。)

For example, we use JNDI to get a connection pool from which to get a jdbc connection, but I could equally create a jdbc connection directly. The later is fine for testing or for a command-line utility, but it is certainly not fine for a general case (which is why we typically opt for the former, jndi-based option.)

使用JMS,是的,你确实需要JNDI,但这并不意味着你的客户端需要在EE容器中。查看Oracle / Sun站点上的JMS教程,并查看简单示例部分:

With JMS, yep, you indeed need JNDI, but that doesn't mean your client needs to be in a EE container. Take a look at the JMS tutorial at the Oracle/Sun site, and check the simple examples section:

http://download.oracle.com/javaee/1.3/jms/tutorial/1_3_1-fcs/doc/client .html

IIRC,每个示例都显示可以从命令行运行的客户端,以及从命令行传递队列名称和其他参数的位置。应该很容易改进该代码,以便您可以从属性文件或函数调用中的参数加载它们。

IIRC, every example shows clients that can be run from the command line and where you simply pass the queue name and other parameters from the command line. It should be easy to retrofit that code so that you can load them up from a property file or as parameters in a function call.

一旦有了可以访问要访问的JMS队列的命令行客户端,就可以改进该代码,使其作为存储过程运行。是的,您可以使用Java来编写Oracle存储过程......

Once you have a command-line client that can access the JMS queue you want to access to, you can retrofit that code so that it runs as a stored procedure. Yes, you can use Java to write stored procedures with Oracle...

...现在,我认为这是一个可怕的功能,一个太开放了滥用。但是,如果您有合法的需要从PL / SQL访问JMS提供程序,这将是一种方法。

... now, I think that is a horrible feature, one that is way too open to abuse. But, if you have a legitimate need to access a JMS provider from PL/SQL, this would be one way to go.

首先,转换命令行jms客户端进入存储过程。查看有关如何使用Oracle创建基于Java的存储过程的现有文档。

First, convert your command-line jms client into a stored procedure. Check the existing documentation on how to create java-based stored procedures with Oracle.

http://www.stanford.edu/dept/itss/docs/oracle/10g/java.101/b12021/storproc。 htm

http://download.oracle.com/docs/cd/B10501_01/java.920/a96659.pdf

然后有你的PL / SQL代码调用存储过程就像调用任何其他存储过程或SQL语句一样。瞧。

Then have your PL/SQL code call the stored procedure just as they would call any other stored proc or SQL statement. And voila.

我从未做过任何这样的事情,可能会出现问题方式。但是,至少在概念上,它应该是可能的。至少你应该能够创建一个jms命令行实用程序,然后可以将其转换为基于java的存储过程。

I've never done any of this, and there might be problems along the way. However, at least conceptually, it should be possible. At the very least you should be able to create a jms command-line utility that you can then convert into a java-based stored proc.

显然,Oracle有一种称为Oracle高级队列的东西,你可以通过PL / SQL直接访问JMS提供者。

Apparently Oracle has something called "Oracle Advanced Queueing" where you can access a JMS provider directly via PL/SQL.

http://www.akadia.com/services/ora_advanced_queueing.html

http://technology.amis.nl/blog/2384/enqueuing-aq-jms-text-message-from-plsql-on-oracle-xe

http://download.oracle .com / docs / cd / B10500_01 / appdev.920 / a96587 / qintro.htm

看起来涉及很多阅读和肘部油脂,但它当然是可行的(假设您正在使用正确的Oracle版本。)

Looks like a lot of reading and elbow grease involved, but it is certainly feasible (assuming you are using the right Oracle version.)

这篇关于从PL / SQL调用/使用JMS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆