Ver código fonte

爬取封面添加代理

syh 5 anos atrás
pai
commit
cadd907ebd

+ 6 - 0
jeecg-boot-module-system/pom.xml

@@ -36,6 +36,12 @@
     </repositories>
 
     <dependencies>
+        <!-- rabbitmq 依赖jar包-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+            <version>1.5.2.RELEASE</version>
+        </dependency>
         <dependency>
             <groupId>org.jeecgframework.boot</groupId>
             <artifactId>jeecg-boot-base-common</artifactId>

+ 65 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/config/RabbitConfig.java

@@ -0,0 +1,65 @@
+package org.jeecg.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Queue;
+import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.config.ConfigurableBeanFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+
+@Configuration
+@Slf4j
+public class RabbitConfig {
+    @Value("${spring.rabbitmq.host}")
+    private String host;
+
+    @Value("${spring.rabbitmq.port}")
+    private int port;
+
+    @Value("${spring.rabbitmq.username}")
+    private String username;
+
+    @Value("${spring.rabbitmq.password}")
+    private String password;
+
+
+    public static final String EXCHANGE_A = "my-mq-exchange_A";
+    public static final String EXCHANGE_B = "my-mq-exchange_B";
+    public static final String EXCHANGE_C = "my-mq-exchange_C";
+
+
+    public static final String QUEUE_A = "QUEUE_A";
+    public static final String QUEUE_B = "QUEUE_B";
+    public static final String QUEUE_C = "QUEUE_C";
+
+    public static final String ROUTINGKEY_A = "spring-boot-routingKey_A";
+    public static final String ROUTINGKEY_B = "spring-boot-routingKey_B";
+    public static final String ROUTINGKEY_C = "spring-boot-routingKey_C";
+
+    @Bean
+    public ConnectionFactory connectionFactory() {
+        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
+        connectionFactory.setUsername(username);
+        connectionFactory.setPassword(password);
+        connectionFactory.setVirtualHost("/");
+        connectionFactory.setPublisherConfirms(true);
+        return connectionFactory;
+    }
+
+    @Bean
+    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+    //必须是prototype类型
+    public RabbitTemplate rabbitTemplate() {
+        RabbitTemplate template = new RabbitTemplate(connectionFactory());
+        return template;
+    }
+
+    @Bean
+    public Queue helloQueue() {
+        return new Queue("hello");
+    }
+}

+ 2 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -100,9 +100,10 @@ public class ShiroConfig {
 		filterChainDefinitionMap.put("/actuator/metrics/**", "anon");
 		filterChainDefinitionMap.put("/actuator/httptrace/**", "anon");
 		filterChainDefinitionMap.put("/actuator/redis/**", "anon");
+        //消息队列
+        filterChainDefinitionMap.put("/mq/**", "anon");
         //模板测试
         filterChainDefinitionMap.put("/test/**", "anon");
-        //报表测试
 		//oauth接口
         filterChainDefinitionMap.put("/auth/**", "anon");
 		filterChainDefinitionMap.put("/ctop/syncdata/**", "anon");

+ 0 - 19
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ActorController.java

@@ -42,25 +42,6 @@ public class ActorController {
     public Result<Actor> getDetail(@RequestParam(name = "actorId") Long actorId) {
         Result<Actor> result = new Result<>();
         Actor actor = actorService.getById(actorId);
-//        ActorComment actorComment = new ActorComment();
-//        actorComment.setActorId(actorId);
-//        QueryWrapper<ActorComment> actorCommentQueryWrapper = QueryGenerator.initQueryWrapper(actorComment, null);
-//        List<ActorComment> actorCommentList = actorCommentService.list(actorCommentQueryWrapper);
-//
-//        ActorPhoto actorPhoto = new ActorPhoto();
-//        actorPhoto.setActorId(actorId);
-//        QueryWrapper<ActorPhoto> actorPhotoQueryWrapper = QueryGenerator.initQueryWrapper(actorPhoto, null);
-//        List<ActorPhoto> actorPhotoList = actorPhotoService.list(actorPhotoQueryWrapper);
-//
-//        ActorVideo actorVideo = new ActorVideo();
-//        actorVideo.setActorId(actorId);
-//        QueryWrapper<ActorVideo> actorVideoQueryWrapper = QueryGenerator.initQueryWrapper(actorVideo, null);
-//        List<ActorVideo> actorVideoList = actorVideoService.list(actorVideoQueryWrapper);
-//        Map<String, Object> map = new HashMap<String, Object>();
-//        map.put("actor", actor);
-//        map.put("actorCommentList", actorCommentList);
-//        map.put("actorPhotoList", actorPhotoList);
-//        map.put("actorVideoList", actorVideoList);
         result.setResult(actor);
         result.setSuccess(true);
         return result;

+ 49 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestMqController.java

@@ -0,0 +1,49 @@
+package org.jeecg.modules.ctop.controller;
+
+import cn.com.ctop.common.module.utils.ResultMapUtils;
+import cn.com.ctop.common.module.utils.StatusCode;
+import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
+import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
+import org.jeecg.modules.mq.Sender;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@RestController
+@RequestMapping("mq")
+public class TestMqController {
+    @Autowired
+    private Sender sender;
+    @Autowired
+    private IAppiumJobService jobService;
+    @Autowired
+    private IAppiumTaskService appiumTaskService;
+
+    @GetMapping("hello")
+    public Map<String, Object> sayHello() {
+        Map<String, Object> result = new HashMap<>();
+        sender.send();
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS.getCode());
+        return result;
+    }
+
+    @GetMapping("task1")
+    public Map<String, Object> task1() {
+        Map<String, Object> result = new HashMap<>();
+        jobService.loginTask(2L);
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS.getCode());
+        return result;
+    }
+
+    @GetMapping("task2")
+    public Map<String, Object> task2() {
+        Map<String, Object> result = new HashMap<>();
+        appiumTaskService.runTask(1, 1);
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS.getCode());
+        return result;
+    }
+}

+ 17 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/mq/Receiver.java

@@ -0,0 +1,17 @@
+package org.jeecg.modules.mq;
+
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+@Component
+@RabbitListener(queues = "hello")
+public class Receiver {
+    /**
+     * 通过@RabbitHandler声明的方法,对hello队列中的消息进行处理
+     */
+    @RabbitHandler
+    public void receiver(String str) {
+        System.out.println("Receiver says:[" + str + "]");
+    }
+}

+ 21 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/mq/Sender.java

@@ -0,0 +1,21 @@
+package org.jeecg.modules.mq;
+
+import org.springframework.amqp.core.AmqpTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Sender {
+
+    @Autowired
+    AmqpTemplate rabbitmqTemplate;
+
+    /**
+     * 发送消息
+     */
+    public void send() {
+        String content = "Sender says:" + "'hello, I'm sender'";
+        System.out.println(content);
+        rabbitmqTemplate.convertAndSend("hello", content);
+    }
+}

+ 5 - 0
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -13,6 +13,11 @@ management:
         include: metrics,httptrace
 
 spring:
+  rabbitmq:
+    host: 39.106.184.70
+    port: 5672
+    username: guest
+    password: guest
   servlet:
     multipart:
       max-file-size: -1

+ 9 - 2
jeecg-boot-module-system/src/main/resources/application-test.yml

@@ -13,6 +13,11 @@ management:
         include: metrics,httptrace
 
 spring:
+  rabbitmq:
+    host: 127.0.0.1
+    port: 5672
+    username: guest
+    password: guest
   servlet:
     multipart:
       max-file-size: -1
@@ -95,9 +100,11 @@ spring:
       datasource:
         master:
           #          url: jdbc:mysql://192.168.0.23:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
-          url: jdbc:mysql://39.106.184.70:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+          #          url: jdbc:mysql://39.106.184.70:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+          url: jdbc:mysql://33.97.120.42:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
           username: hcst
-          password: hcst2019
+          #          password: hcst2019
+          password: test@20190531
           driver-class-name: com.mysql.jdbc.Driver
           # 多数据源配置
           #multi-datasource1:

+ 7 - 0
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -6,6 +6,7 @@ import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.jeecg.modules.ctop.service.ICreateInternalService;
+import org.jeecg.modules.mq.Sender;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.openqa.selenium.By;
@@ -119,4 +120,10 @@ public class SampleTest {
         //3:转化
         appiumTaskService.runTask(1, 1);
     }
+
+    @Test
+    public void testMq() {
+        Sender sender = new Sender();
+        sender.send();
+    }
 }