我有一个Java服务,它从表'A‘读取数据(包括BLOB),将这些数据写入表'B’,然后将BLOB作为ByteArrayInputStream上传到存储服务器(基本上是一个小型迁移服务)。成功完成上载过程后,两个表上的布尔列都设置为1。该服务的工作方式是将POST请求发送到REST服务器,并且对于复制的每一行,都会返回一个location头作为响应。处理POST请求的资源方法如下所示。
@POST
@Produces({MediaType.APPLICATION_JSON})
public Response migrateToMinio(@Context UriInfo uriInfo) throws Exception {
tiedostoService = new TiedostoService();
attachmentService = new AttachmentService();
List<Tiedosto> tiedostoList = tiedostoService.getAllFiles();
List<String> responseList = new ArrayList<>();
Response r;
Integer newRow;
String responseData = null;
int i=1;
for (Tiedosto tiedosto : tiedostoList) {
Attachment attachment = new Attachment();
attachment.setCustomerId(tiedosto.getCustomerId());
attachment.setSize(tiedosto.getFileSize());
newRow = attachmentService.createNew(attachment);
UriBuilder builder = uriInfo.getAbsolutePathBuilder();
if (newRow == 1) {
builder.path(Integer.toString(i));
r = Response.created(builder.build()).build();
responseData = r.getLocation().toString();
i++;
}
responseList.add(responseData);
}
String jsonString = new Gson().toJson(responseList);
return Response.status(Response.Status.OK).entity(jsonString).build();
}
首先,通过POST生成一个JWT到api,并使用该作为持有者令牌,另一个POST被发送到"/rest/attachments",它在花费一段时间进行处理后返回状态200,如下所示。
我的问题是,我如何实现一个java后台服务(就像运行在与服务器相同的物理机上的客户端),它会自动将POST请求发送到REST服务器进行迁移过程?在第一次运行时,后台服务应该处理整个表,然后后台服务需要定期运行,以检查是否向表中添加了新行,并对其进行相应的处理。我是一个Java新手,真的很感谢任何形式的帮助/建议。
https://stackoverflow.com/questions/52020174
复制相似问题