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

2023-12-17 19:01

本文主要是介绍oracle aq java jms使用(数据类型为XMLTYPE),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

记录一次冷门技术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;
begindbms_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;

创建列队表

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

创建列队及启动队列

begindbms_aqadm.create_queue (queue_name  => 'testaq.xml_queue',queue_table => 'testaq.xml_queue_table');dbms_aqadm.start_queue(queue_name  =>  'testaq.xml_queue');
end;

停止及删除队列

begindbms_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;

发送消息

declarer_enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T;r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;v_message_handle RAW(16);o_payload SYS.XMLTYPE;
begino_payload := SYS.XMLTYPE('<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:testaqusername: testaqpassword: 123456queueNameUser: testaqqueueName: 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 {@Autowiredprivate OracleAqJmsConfig config;@PostConstructpublic 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() {@Overridepublic 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 -->

这篇关于oracle aq java jms使用(数据类型为XMLTYPE)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/505481

相关文章

一文详解SpringBoot中控制器的动态注册与卸载

《一文详解SpringBoot中控制器的动态注册与卸载》在项目开发中,通过动态注册和卸载控制器功能,可以根据业务场景和项目需要实现功能的动态增加、删除,提高系统的灵活性和可扩展性,下面我们就来看看Sp... 目录项目结构1. 创建 Spring Boot 启动类2. 创建一个测试控制器3. 创建动态控制器注

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Java操作Word文档的全面指南

《Java操作Word文档的全面指南》在Java开发中,操作Word文档是常见的业务需求,广泛应用于合同生成、报表输出、通知发布、法律文书生成、病历模板填写等场景,本文将全面介绍Java操作Word文... 目录简介段落页头与页脚页码表格图片批注文本框目录图表简介Word编程最重要的类是org.apach

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建

SpringBoot+Docker+Graylog 如何让错误自动报警

《SpringBoot+Docker+Graylog如何让错误自动报警》SpringBoot默认使用SLF4J与Logback,支持多日志级别和配置方式,可输出到控制台、文件及远程服务器,集成ELK... 目录01 Spring Boot 默认日志框架解析02 Spring Boot 日志级别详解03 Sp

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合