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

相关文章

MySQL 日期时间格式化函数 DATE_FORMAT() 的使用示例详解

《MySQL日期时间格式化函数DATE_FORMAT()的使用示例详解》`DATE_FORMAT()`是MySQL中用于格式化日期时间的函数,本文详细介绍了其语法、格式化字符串的含义以及常见日期... 目录一、DATE_FORMAT()语法二、格式化字符串详解三、常见日期时间格式组合四、业务场景五、总结一、

Spring Cloud Hystrix原理与注意事项小结

《SpringCloudHystrix原理与注意事项小结》本文介绍了Hystrix的基本概念、工作原理以及其在实际开发中的应用方式,通过对Hystrix的深入学习,开发者可以在分布式系统中实现精细... 目录一、Spring Cloud Hystrix概述和设计目标(一)Spring Cloud Hystr

Python中配置文件的全面解析与使用

《Python中配置文件的全面解析与使用》在Python开发中,配置文件扮演着举足轻重的角色,它们允许开发者在不修改代码的情况下调整应用程序的行为,下面我们就来看看常见Python配置文件格式的使用吧... 目录一、INI配置文件二、YAML配置文件三、jsON配置文件四、TOML配置文件五、XML配置文件

Go使用pprof进行CPU,内存和阻塞情况分析

《Go使用pprof进行CPU,内存和阻塞情况分析》Go语言提供了强大的pprof工具,用于分析CPU、内存、Goroutine阻塞等性能问题,帮助开发者优化程序,提高运行效率,下面我们就来深入了解下... 目录1. pprof 介绍2. 快速上手:启用 pprof3. CPU Profiling:分析 C

MySQL InnoDB引擎ibdata文件损坏/删除后使用frm和ibd文件恢复数据

《MySQLInnoDB引擎ibdata文件损坏/删除后使用frm和ibd文件恢复数据》mysql的ibdata文件被误删、被恶意修改,没有从库和备份数据的情况下的数据恢复,不能保证数据库所有表数据... 参考:mysql Innodb表空间卸载、迁移、装载的使用方法注意!此方法只适用于innodb_fi

Spring Boot整合消息队列RabbitMQ的实现示例

《SpringBoot整合消息队列RabbitMQ的实现示例》本文主要介绍了SpringBoot整合消息队列RabbitMQ的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的... 目录RabbitMQ 简介与安装1. RabbitMQ 简介2. RabbitMQ 安装Spring

springMVC返回Http响应的实现

《springMVC返回Http响应的实现》本文主要介绍了在SpringBoot中使用@Controller、@ResponseBody和@RestController注解进行HTTP响应返回的方法,... 目录一、返回页面二、@Controller和@ResponseBody与RestController

JAVA集成本地部署的DeepSeek的图文教程

《JAVA集成本地部署的DeepSeek的图文教程》本文主要介绍了JAVA集成本地部署的DeepSeek的图文教程,包含配置环境变量及下载DeepSeek-R1模型并启动,具有一定的参考价值,感兴趣的... 目录一、下载部署DeepSeek1.下载ollama2.下载DeepSeek-R1模型并启动 二、J

Python中conda虚拟环境创建及使用小结

《Python中conda虚拟环境创建及使用小结》本文主要介绍了Python中conda虚拟环境创建及使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录0.前言1.Miniconda安装2.conda本地基本操作3.创建conda虚拟环境4.激活c

springboot rocketmq配置生产者和消息者的步骤

《springbootrocketmq配置生产者和消息者的步骤》本文介绍了如何在SpringBoot中集成RocketMQ,包括添加依赖、配置application.yml、创建生产者和消费者,并展... 目录1. 添加依赖2. 配置application.yml3. 创建生产者4. 创建消费者5. 使用在