初始化队列
This commit is contained in:
parent
f1fba63e8c
commit
5766c52d40
4
pom.xml
4
pom.xml
|
@ -25,6 +25,10 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
|
|
|
@ -3,10 +3,12 @@ package com.example.chat;
|
|||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||
|
||||
//@EnableWebSocket
|
||||
@Mapper
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
public class ChatApplication {
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package com.example.chat.common;
|
||||
|
||||
public class Test {
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.example.chat.common.config;
|
||||
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class RabbitMqConfig {
|
||||
|
||||
public static final String QUEUE_INFORM_SMS = "queue_inform_sms";
|
||||
public static final String EXCHANGE_TOPICS_INFORM = "exchange_topics_inform";
|
||||
public static final String ROUTING_KEY_SMS = "inform.cool.sms.message";
|
||||
|
||||
@Bean(QUEUE_INFORM_SMS)
|
||||
public Queue smsQueue() {
|
||||
return new Queue(QUEUE_INFORM_SMS);
|
||||
}
|
||||
|
||||
@Bean(EXCHANGE_TOPICS_INFORM)
|
||||
public Exchange taskExchange() {
|
||||
return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Binding bindingSMSQueue(@Qualifier(QUEUE_INFORM_SMS) Queue queue,
|
||||
@Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange
|
||||
) {
|
||||
return BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY_SMS).noargs();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package com.example.chat.dao;
|
||||
|
||||
import com.example.chat.dao.mybatis.MybatisSingleton;
|
||||
import com.example.chat.entity.User;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class Test01 implements CommandLineRunner {
|
||||
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
while (true) {
|
||||
SqlSession sqlSession = MybatisSingleton.getSqlSessionFactory().openSession();
|
||||
User user = sqlSession.selectOne("dao.Login.getUser", "img/123/123");
|
||||
if (user != null) {
|
||||
System.out.println(user);
|
||||
}
|
||||
sqlSession.close();
|
||||
System.out.println("sleep");
|
||||
TimeUnit.MINUTES.sleep(10);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.example.chat.service;
|
||||
|
||||
import com.example.chat.common.config.RabbitMqConfig;
|
||||
import com.example.chat.entity.chat.Message;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
@Autowired
|
||||
RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Scheduled(cron = "0 * 23 * * ?")
|
||||
public void test() throws JsonProcessingException {
|
||||
Message message = new Message();
|
||||
message.setMessage("哈哈哈哈哈哈");
|
||||
ObjectMapper mapper=new ObjectMapper();
|
||||
rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_TOPICS_INFORM,RabbitMqConfig.ROUTING_KEY_SMS,mapper.writeValueAsString(message));
|
||||
System.out.println("test定时任务执行了123");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.example.chat.test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Test01 {
|
||||
|
||||
@Test
|
||||
public void Test11(){
|
||||
String currentDir = System.getProperty("user.dir");
|
||||
System.out.println("当前项目的路径是:" + currentDir+"\\com\\example");
|
||||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
String currentDir1 = classLoader.getResource("").getPath();
|
||||
System.out.println("当前项目的路径是:" + currentDir1);
|
||||
|
||||
}
|
||||
}
|
|
@ -5,3 +5,9 @@ spring:
|
|||
port: 6379
|
||||
password: ob666666
|
||||
host: 119.29.254.99
|
||||
rabbitmq:
|
||||
host: 119.29.254.99
|
||||
port: 5672
|
||||
username: cool
|
||||
password: cool
|
||||
virtualHost: /
|
||||
|
|
Loading…
Reference in New Issue