11
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.njcn.roma.client;
|
package com.njcn.roma.client;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.huawei.it.eip.ump.client.consumer.ConsumeStatus;
|
import com.huawei.it.eip.ump.client.consumer.ConsumeStatus;
|
||||||
import com.huawei.it.eip.ump.client.consumer.Consumer;
|
import com.huawei.it.eip.ump.client.consumer.Consumer;
|
||||||
import com.huawei.it.eip.ump.client.listener.MessageListener;
|
import com.huawei.it.eip.ump.client.listener.MessageListener;
|
||||||
@@ -7,6 +9,8 @@ import com.huawei.it.eip.ump.common.exception.UmpException;
|
|||||||
import com.huawei.it.eip.ump.common.message.Message;
|
import com.huawei.it.eip.ump.common.message.Message;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,6 +25,8 @@ public class ClientHandler extends Thread {
|
|||||||
private Consumer consumer;
|
private Consumer consumer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (consumer == null) {
|
if (consumer == null) {
|
||||||
@@ -39,6 +45,27 @@ public class ClientHandler extends Thread {
|
|||||||
// 消费消息的业务逻辑
|
// 消费消息的业务逻辑
|
||||||
try {
|
try {
|
||||||
System.out.println("Receive: " + new String(message.getBody(), "UTF-8"));
|
System.out.println("Receive: " + new String(message.getBody(), "UTF-8"));
|
||||||
|
// 指定要写入的文件路径
|
||||||
|
String filePath = "message.text";
|
||||||
|
String filePath2 = "body.text";
|
||||||
|
|
||||||
|
try (FileWriter file = new FileWriter(filePath)) {
|
||||||
|
|
||||||
|
// 将 JSON 字符串写入文件
|
||||||
|
file.write(JSON.toJSONString(message));
|
||||||
|
System.out.println("成功将及格 JSON 数据写入文件:" + filePath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
try (FileWriter file2 = new FileWriter(filePath2)) {
|
||||||
|
|
||||||
|
// 将 JSON 字符串写入文件
|
||||||
|
file2.write(JSON.toJSONString(message.getBody()));
|
||||||
|
System.out.println("成功将及格 JSON 数据写入文件:" + filePath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user