切换导航条
此项目
正在载入...
登录
wlxxpt
/
xmlWithMqProcess
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
朱兆平
4 years ago
提交
ece32c7dda6dd70539aae9d562ca61eaf7ecb32a
1 个父辈
9031193f
nmmsProcess
发送报文时采用报文中的messageid生成报文名称,
将回执发到队列时,进行xml格式的判定
显示空白字符变更
内嵌
并排对比
正在显示
5 个修改的文件
包含
38 行增加
和
14 行删除
src/main/java/com/tianbo/analysis/handle/SendXml2MqThread.java
src/main/java/com/tianbo/analysis/rabbitmq/GetResponse.java
src/main/java/com/tianbo/analysis/task/CustomMqGetTask.java
src/main/java/com/tianbo/analysis/task/TCSMqGetTask.java
src/main/java/com/tianbo/analysis/task/TCSMqSendTask.java
src/main/java/com/tianbo/analysis/handle/SendXml2MqThread.java
查看文件 @
ece32c7
...
...
@@ -17,13 +17,13 @@ import org.dom4j.Element;
import
org.dom4j.io.SAXReader
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.xml.sax.InputSource
;
import
org.xml.sax.SAXParseException
;
import
javax.annotation.PostConstruct
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
java.io.*
;
import
java.util.concurrent.CountDownLatch
;
/**
...
...
@@ -99,6 +99,8 @@ public class SendXml2MqThread implements Runnable{
int
i
=
0
;
String
content
=
FileUtils
.
readFileToString
(
xmlfile
,
"UTF-8"
);
//校验报文格式是否是XML
if
(
isXmlDocument
(
content
)){
/**
* 发送消息到交换上
*/
...
...
@@ -116,8 +118,29 @@ public class SendXml2MqThread implements Runnable{
);
return
success
?
1
:
0
;
}
else
{
log
.
info
(
"[{}]报文格式未通过XML校验,报文删除"
,
content
);
return
1
;
}
}
/**
* 校验字符窜是否是XML格式
* @param rtnMsg
* @return
*/
private
static
boolean
isXmlDocument
(
String
rtnMsg
){
boolean
flag
=
true
;
try
{
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
builder
=
documentBuilderFactory
.
newDocumentBuilder
();
builder
.
parse
(
new
InputSource
(
new
StringReader
(
rtnMsg
)));
}
catch
(
Exception
e
)
{
flag
=
false
;
}
return
flag
;
}
}
...
...
src/main/java/com/tianbo/analysis/rabbitmq/GetResponse.java
查看文件 @
ece32c7
...
...
@@ -62,8 +62,8 @@ public class GetResponse extends DefaultConsumer {
this
.
mqResponse
=
new
MqResponse
(
consumerTag
,
envelope
,
properties
,
new
String
(
body
,
StandardCharsets
.
UTF_8
));
log
.
info
(
"-----------获取到报文----------\n{}"
,
mqResponse
.
getContent
());
handleMessage
(
mqResponse
.
getContent
());
// writeToReadDir(mqResponse.getContent());
// handleMessage(mqResponse.getContent());
writeToReadDir
(
mqResponse
.
getContent
());
//写入回执目录
}
...
...
@@ -71,19 +71,20 @@ public class GetResponse extends DefaultConsumer {
public
void
writeToReadDir
(
String
content
)
throws
IOException
{
if
(
content
!=
null
&&
!
content
.
isEmpty
()){
//todo:下边过去xml文件报头代码在TCS服务器上部署的时候最好去掉.这段过滤代码是为了能转发到IMF
content
=
content
.
replace
(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
,
""
);
//
content = content.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>","");
//查找报文中的messageid作为文件名
String
pattern
=
"<MessageID>(\\w+)</MessageID>"
;
Pattern
r
=
Pattern
.
compile
(
pattern
);
Matcher
matcher
=
r
.
matcher
(
content
);
String
fileName
=
this
.
receptDir
+
UUID
.
randomUUID
().
toString
()+
".xml"
;
// 新舱单部署要去掉下面更改名称代码
// if (matcher.find()){
// fileName = this.receptDir+ matcher.group(1)+".xml";
// }
log
.
info
(
"-----------{}报文保存成功----------"
,
fileName
);
if
(
matcher
.
find
()){
fileName
=
this
.
receptDir
+
matcher
.
group
(
1
)+
".xml"
;
}
File
fileToDirectory
=
new
File
(
fileName
);
FileUtils
.
writeStringToFile
(
fileToDirectory
,
content
,
"UTF-8"
);
log
.
info
(
"-----------{}报文保存成功----------"
,
fileName
);
}
}
...
...
src/main/java/com/tianbo/analysis/task/CustomMqGetTask.java
查看文件 @
ece32c7
...
...
@@ -50,7 +50,7 @@ public class CustomMqGetTask {
@Value
(
"${mq.exchange.routing-key}"
)
private
String
routingKey
;
@Scheduled
(
fixedRate
=
5000
)
//
@Scheduled(fixedRate = 5000)
public
void
startTask
(){
try
{
...
...
src/main/java/com/tianbo/analysis/task/TCSMqGetTask.java
查看文件 @
ece32c7
...
...
@@ -40,7 +40,7 @@ public class TCSMqGetTask {
@Value
(
"${mq.queue.read-from-mq}"
)
private
String
queueName
;
//
@Scheduled(fixedRate = 5000)
@Scheduled
(
fixedRate
=
5000
)
public
void
startTask
(){
...
...
src/main/java/com/tianbo/analysis/task/TCSMqSendTask.java
查看文件 @
ece32c7
...
...
@@ -57,7 +57,7 @@ public class TCSMqSendTask {
*/
private
final
static
int
theadamount
=
10
;
//
@Scheduled(fixedRate = 5000)
@Scheduled
(
fixedRate
=
5000
)
public
void
startTask
(){
final
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
...
...
请
注册
或
登录
后发表评论