oracle aq java jms使用(数据类型为XMLTYPE)

news2024/9/22 19:29:39

记录一次冷门技术oracle aq的使用

版本

oracle 11g

创建用户

-- 创建用户
create user testaq identified by 123456;
grant connect, resource to testaq;

-- 创建aq所需要的权限
grant execute on dbms_aq to testaq;
grant execute on dbms_aqadm to testaq;
begin
  dbms_aqadm.grant_system_privilege('enqueue_any', 'testaq', false);
  dbms_aqadm.grant_system_privilege('dequeue_any', 'testaq', false);
end;

grant execute on dbms_aq to testaq;
grant resource to testaq;
grant connect to testaq;
grant execute any procedure to testaq;
grant aq_administrator_role to testaq;
grant aq_user_role to testaq;
grant execute on dbms_aqadm to testaq;
grant execute on dbms_aq to testaq;
grant execute on dbms_aqin to testaq;
grant create procedure to testaq;
grant create procedure to testaq with admin option;

创建列队表

begin
  dbms_aqadm.create_queue_table(
    queue_table   => 'testaq.xml_queue_table',
    queue_payload_type => 'SYS.XMLTYPE',
    multiple_consumers => false
  );
end;

创建列队及启动队列

begin
  dbms_aqadm.create_queue (
    queue_name  => 'testaq.xml_queue',
    queue_table => 'testaq.xml_queue_table'
  );

  dbms_aqadm.start_queue(
    queue_name  =>  'testaq.xml_queue'
  );
end;

停止及删除队列

begin
  dbms_aqadm.stop_queue (queue_name => 'testaq.xml_queue');
  dbms_aqadm.drop_queue (queue_name => 'testaq.xml_queue');
  dbms_aqadm.drop_queue_table (queue_table => 'testaq.xml_queue_table');
end;

发送消息

declare
  r_enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
  r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
  v_message_handle RAW(16);
  o_payload testaq.test_queue_type;
begin
  o_payload := testaq.test_queue_type('<ROOT><ROWSET><ROW><APPLYNO>test</APPLYNO></ROW></ROWSET></ROOT>');

  dbms_aq.enqueue(
    queue_name  => 'testaq.test_queue',
    enqueue_options => r_enqueue_options,
    message_properties => r_message_properties,
    payload => o_payload,
    msgid => v_message_handle
  );
   commit;
end;

Java接收消息

oracle-aq:
  jdbcUrl: jdbc:oracle:thin:@localhost:1521:testaq
  username: testaq
  password: 123456
  queueNameUser: testaq
  queueName: xml_queue
@Component
@ConfigurationProperties(prefix = "oracle-aq")
@Data
public class OracleAqJmsConfig {
    private String jdbcUrl;
    private String username;
    private String password;
    private String queueNameUser;
    private String queueName;
}
import lombok.extern.slf4j.Slf4j;
import oracle.jms.AQjmsAdtMessage;
import oracle.jms.AQjmsDestination;
import oracle.jms.AQjmsFactory;
import oracle.jms.AQjmsSession;
import oracle.xdb.XMLType;
import oracle.xdb.XMLTypeFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import javax.jms.*;
import javax.xml.bind.JAXBException;
import java.util.Properties;

@Service
@Slf4j
public class TestOracleAq {

    @Autowired
    private OracleAqJmsConfig config;

    @PostConstruct
    public void messageListener() throws JMSException {
        QueueConnectionFactory queueConnectionFactory = AQjmsFactory.getQueueConnectionFactory(config.getJdbcUrl(), new Properties());
        QueueConnection conn = queueConnectionFactory.createQueueConnection(config.getUsername(), config.getPassword());
        AQjmsSession session = (AQjmsSession)conn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
        conn.start();
        Queue queue = (AQjmsDestination)session.getQueue(config.getQueueNameUser(), config.getQueueName());
        XMLTypeFactory factory = new XMLTypeFactory();
        MessageConsumer consumer = session.createConsumer(queue, null, factory, null, false);
        consumer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                AQjmsAdtMessage adtMessage = (AQjmsAdtMessage) message;
                try {
                    Object adtPayload = adtMessage.getAdtPayload();
                    XMLType xmlType = (XMLType)adtPayload;
                    saveXml(xmlType.getStringVal());
                    log.info("接收到oracle aq数据:{}", xmlType.getStringVal());
                } catch (Exception e) {
                    log.error("", e);
                }
            }
        });
    }

    public void saveXml(String xml) throws JAXBException {
        // todo ...
    }

}

依赖

在oracle安装目录中查找这些依赖
在这里插入图片描述

<!-- oracle aq -->
 <dependency>
	<groupId>com.oracle</groupId>
	<artifactId>ojdbc6</artifactId>
	<version>11.1.0.7.0</version>
	<scope>system</scope>
    <systemPath>${project.basedir}/libs/ojdbc6.jar</systemPath>
</dependency>
<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>jmscommon</artifactId>
	<version>1.0</version>
	<scope>system</scope>
    <systemPath>${project.basedir}/libs/jmscommon.jar</systemPath>
</dependency>
<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>orai18n</artifactId>
	<version>11.1.0.7.0</version>
	<scope>system</scope>
    <systemPath>${project.basedir}/libs/orai18n.jar</systemPath>
</dependency>
<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>jta</artifactId>
	<version>1.0</version>
	<scope>system</scope>
    <systemPath>${project.basedir}/libs/jta.jar</systemPath>
</dependency>
<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>aqapi_g</artifactId>
	<version>1.0</version>
	<scope>system</scope>
    <systemPath>${project.basedir}/libs/aqapi_g.jar</systemPath>
</dependency>
<dependency>
     <groupId>oracle.xdb</groupId>
    <artifactId>xdb</artifactId>
	<version>21.9.0.0</version>
	<scope>system</scope>
    <systemPath>${project.basedir}/libs/xdb.jar</systemPath>
</dependency>
<!-- oracle aq -->

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1311588.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

android studio 快捷输入模板提示

在Android开发中&#xff0c;我们经常会遇到一些重复性的代码&#xff0c;例如创建一个新的Activity、定义一个Getter方法等。为了提高开发效率&#xff0c;Android Studio提供了Live Templates功能&#xff0c;可以通过简化输入来快速生成这些重复性代码。 按下图提示设置&am…

GO并发编程综合应用

一.GO并发编程综合应用 1.生产者消费者模式 1.1需求分析 ​ 生产者每秒生产一个商品&#xff0c;并通过物流公司取货 ​ 物流公司将商品运输到商铺 ​ 消费者阻塞等待商铺到货&#xff0c;需要消费10次商品 1.2实现原理 1.3代码实现&#xff1a; package mainimport (&q…

Google DeepMind发布Imagen 2文字到图像生成模型;微软在 HuggingFace 上发布了 Phi-2 的模型

&#x1f989; AI新闻 &#x1f680; Google DeepMind发布Imagen 2文字到图像生成模型 摘要&#xff1a;谷歌的Imagen 2是一种先进的文本到图像技术&#xff0c;可以生成与用户提示紧密对齐的高质量、逼真的图像。它通过使用训练数据的自然分布来生成更逼真的图像&#xff0c…

服务器上配置jupyter,提示Invalid credentials如何解决

我是按照网上教程在服务器上安装的jupyter以及进行的密码配置&#xff0c;我利用 passwd()这个口令生成的转译密码是"argon...."。按照教程配置jupyter notebook配置文件里面的内容&#xff0c;登陆网页提示"Invalid credentials"。我谷歌得到的解答是&…

07用户行为日志数据采集

用户行为数据由Flume从Kafka直接同步到HDFS&#xff0c;由于离线数仓采用Hive的分区表按天统计&#xff0c;所以目标路径要包含一层日期。具体数据流向如下图所示。 按照规划&#xff0c;该Flume需将Kafka中topic_log的数据发往HDFS。并且对每天产生的用户行为日志进行区分&am…

cfa一级考生复习经验分享系列(三)

从总成绩可以看出&#xff0c;位于90%水平之上&#xff0c;且置信区间全体均高于90%线。 从各科目成绩可以看出&#xff0c;所有科目均位于90%线上或高于90%线&#xff0c;其中&#xff0c;另类与衍生、公司金额、经济学、权益投资、固定收益、财报分析表现较好&#xff0c;目测…

多架构容器镜像构建实战

最近在一个国产化项目中遇到了这样一个场景&#xff0c;在同一个 Kubernetes 集群中的节点是混合架构的&#xff0c;也就是说&#xff0c;其中某些节点的 CPU 架构是 x86 的&#xff0c;而另一些节点是 ARM 的。为了让我们的镜像在这样的环境下运行&#xff0c;一种最简单的做法…

双端队列和优先级队列

文章目录 前言dequedeque底层设计迭代器设计 priority仿函数数组中的第k个最大元素优先级队列模拟实现pushpop调整仿函数存储自定义类型 前言 今天要介绍比较特殊的结构&#xff0c;双端队列。 还有一个适配器&#xff0c;优先级队列。 deque 栈的默认容器用了一个deque的东西…

案例课7——百度智能客服

1.公司介绍 百度智能客服是百度智能云推出的将AI技术赋能企业客服业务的一揽子解决方案。该方案基于百度世界先进的语音技术、自然语言理解技术、知识图谱等构建完备的一体化产品方案&#xff0c;结合各行业头部客户丰富的运营经验&#xff0c;持续深耕机场服务、电力调度等场…

【普中】基于51单片机简易计算器显示设计( proteus仿真+程序+设计报告+实物演示+讲解视频)

目录标题 &#x1f4df;1. 主要功能&#xff1a;&#x1f4df;2. 讲解视频&#xff1a;&#x1f4df;3. 设计说明书(报告)&#x1f4df;4. 仿真&#x1f4df;5. 实物烧录和现象&#x1f4df;6. 程序代码&#x1f4df;7. 设计资料内容清单 【普中开发板】基于51单片机简易计算器…

日志框架Log4j、JUL、JCL、Slf4j、Logback、Log4j2

为什么程序需要记录日志 我们不可能实时的24小时对系统进行人工监控&#xff0c;那么如果程序出现异常错误时要如何排查呢&#xff1f;并且系统在运行时做了哪些事情我们又从何得知呢&#xff1f;这个时候日志这个概念就出现了&#xff0c;日志的出现对系统监控和异常分析起着…

Jenkins 添加节点报错

报错日志 Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher has been compiled by a more recent version of the Java Runtime (cl…

react+datav+echarts实现可视化数据大屏

&#x1f4d3;最近有点闲&#xff0c;就学习了下react&#xff0c;没想到就把react学完了&#xff0c;觉得还不错&#xff0c;就打算出一把reactdatav的简易版可视化数据大屏供大家做个参考。 &#x1f4d3;效果如下 1下载必要的框架 &#x1f4d3; react路由 npm install re…

Rancher中使用promtail+loki+grafna收集k8s日志并展示

Rancher中使用promtail+loki+grafna收集k8s日志并展示 根据应用需求和日志数量级别选择对应的日志收集、过滤和展示方式,当日志量不太大,又想简单集中管理查看日志时,可使用promtail+loki+grafna的方式。本文找那个loki和grafana外置在了k8s集群之外。 1、添加Chart Repo …

js解析.shp文件

效果图 原理与源码 本文采用的是shapefile.js工具 这里是他的npm地址 https://www.npmjs.com/package/shapefile 这是他的unpkg地址&#xff0c;可以点开查看源码 https://unpkg.com/shapefile0.6.6/dist/shapefile.js 这个最关键的核心问题是如何用这个工具&#xff0c;网上…

[开源更新] 企业级身份管理和访问管理系统、为数字身份安全赋能

一、系统简介 名称&#xff1a;JNPF权限管理系统 JNPF 权限管理系统可用于管理企业内员工账号、权限、身份认证、应用访问等&#xff0c;可整合部署在本地或云端的内部办公系统、业务系统及第三方 SaaS 系统的所有身份&#xff0c;实现一个账号打通所有应用的服务。其有如下几…

【Docker】WSL 2 上的 Docker 搭建和入门

▒ 目录 ▒ &#x1f6eb; 导读开发环境 1️⃣ 安装安装Docker Desktop for Windows 2️⃣ 环境配置3️⃣ hello world第一次运行再次运行分析总结 &#x1f4d6; 参考资料 &#x1f6eb; 导读 开发环境 版本号描述文章日期2023-12-14操作系统Win11 - 22H222621.2715WSL2 C:…

60.Sentinel源码分析

Sentinel源码分析 1.Sentinel的基本概念 Sentinel实现限流、隔离、降级、熔断等功能&#xff0c;本质要做的就是两件事情&#xff1a; 统计数据&#xff1a;统计某个资源的访问数据&#xff08;QPS、RT等信息&#xff09; 规则判断&#xff1a;判断限流规则、隔离规则、降级规…

单片机——通信协议(FPGA+c语言应用之spi协议解析篇)

引言 串行外设接口(SPI)是微控制器和外围IC&#xff08;如传感器、ADC、DAC、移位寄存器、SRAM等&#xff09;之间使用最广泛的接口之一。本文先简要说明SPI接口&#xff0c;然后介绍ADI公司支持SPI的模拟开关与多路转换器&#xff0c;以及它们如何帮助减少系统电路板设计中的数…

在接口实现类中,加不加@Override的区别

最近的软件构造实验经常需要设计接口&#xff0c;我们知道Override注解是告诉编译器&#xff0c;下面的方法是重写父类的方法&#xff0c;那么单纯实现接口的方法需不需要加Override呢&#xff1f; 定义一个类实现接口&#xff0c;使用idea时&#xff0c;声明implements之后会…