|
@@ -1,5 +1,7 @@
|
|
|
package com.fdkankan.download.listener;
|
|
|
|
|
|
+import com.fdkankan.common.util.CmdUtils;
|
|
|
+import com.fdkankan.download.constant.CommonConstant;
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.amqp.core.Message;
|
|
@@ -14,21 +16,36 @@ import java.nio.charset.StandardCharsets;
|
|
|
@Component
|
|
|
public class RsyncSceneListener {
|
|
|
|
|
|
+ public final static String RSYNC_CMD = "rsync -av -e 'ssh -p $port' $source $user@$host:$dest";
|
|
|
+
|
|
|
+ @Value("${rsync.host}")
|
|
|
+ private String host;
|
|
|
+
|
|
|
+ @Value("${rsync.port}")
|
|
|
+ private String port;
|
|
|
+
|
|
|
+ @Value("${rsync.username}")
|
|
|
+ private String username;
|
|
|
+
|
|
|
+ @Value("${rsync.dest}")
|
|
|
+ private String dest;
|
|
|
+
|
|
|
/**
|
|
|
* 场景计算状态日志记录
|
|
|
* @param channel
|
|
|
* @param message
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
-// @RabbitListener(
|
|
|
-// queuesToDeclare = @Queue("rsync-scene"),
|
|
|
-// concurrency = "2"
|
|
|
-// )
|
|
|
-// public void buildScenePreHandler(Channel channel, Message message) throws Exception {
|
|
|
-// String msg = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
-// System.out.println(msg);
|
|
|
-// Thread.sleep(60000L);
|
|
|
-// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
-// }
|
|
|
+ @RabbitListener(
|
|
|
+ queuesToDeclare = @Queue("rsync-scene"),
|
|
|
+ concurrency = "2"
|
|
|
+ )
|
|
|
+ public void buildScenePreHandler(Channel channel, Message message) throws Exception {
|
|
|
+ String path = new String(message.getBody(), StandardCharsets.UTF_8);
|
|
|
+ System.out.println(path);
|
|
|
+ String cmd = RSYNC_CMD.replace("$port", port).replace("$source", path).replace("$user", username).replace("$host", host).replace("$dest", dest);
|
|
|
+ CmdUtils.callLine(cmd);
|
|
|
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
|
|
+ }
|
|
|
|
|
|
}
|