Skip to content

Commit

Permalink
Merge branch '0.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
zjn committed Jul 1, 2021
2 parents c32b993 + 00c0be8 commit c71f0a9
Show file tree
Hide file tree
Showing 35 changed files with 318 additions and 293 deletions.
34 changes: 34 additions & 0 deletions ice-client-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice</artifactId>
<version>0.0.4</version>
</parent>
<packaging>jar</packaging>
<artifactId>ice-client-spring-boot-autoconfigure</artifactId>
<name>ice-client-spring-boot-autoconfigure</name>

<dependencies>
<dependency>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice-client</artifactId>
<version>0.0.4</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ice.client.starter;


import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.ice.client")
public class IceClientAutoConfiguration {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.ice.client.starter.IceClientAutoConfiguration
31 changes: 31 additions & 0 deletions ice-client-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice</artifactId>
<version>0.0.4</version>
</parent>
<packaging>jar</packaging>
<artifactId>ice-client-spring-boot-starter</artifactId>
<name>ice-client-spring-boot-starter</name>

<dependencies>
<dependency>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice-client-spring-boot-autoconfigure</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
</project>
12 changes: 4 additions & 8 deletions ice-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

<parent>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice-parent</artifactId>
<version>0.0.1</version>
<artifactId>ice</artifactId>
<version>0.0.4</version>
</parent>
<packaging>jar</packaging>
<artifactId>ice-client</artifactId>
Expand All @@ -16,31 +16,27 @@
<dependency>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice-core</artifactId>
<version>0.0.1</version>
<version>0.0.4</version>
</dependency>
<!--rabbitmq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
<scope>provided</scope>
<version>1.2.76</version>
</dependency>
</dependencies>
</project>
10 changes: 5 additions & 5 deletions ice-client/src/main/java/com/ice/client/IceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class IceClient {
private IceClient() {
}

/*
/*
* 不关心结果-handler异步执行
*
* @param pack 包裹
Expand All @@ -27,7 +27,7 @@ public static void process(IcePack pack) {
IceDispatcher.asyncDispatcher(pack);
}

/*
/*
* 需要执行后的单个Roam
*
* @param pack 包裹
Expand All @@ -40,7 +40,7 @@ public static IceRoam processSingleRoam(IcePack pack) {
return null;
}

/*
/*
* 需要执行后的Roam列表
*
* @param pack 包裹
Expand All @@ -54,7 +54,7 @@ public static List<IceRoam> processRoam(IcePack pack) {
.collect(Collectors.toCollection(() -> new ArrayList<>(cxts.size())));
}

/*
/*
* 需要执行后的单个cxt
*
* @param pack 包裹
Expand All @@ -67,7 +67,7 @@ public static IceContext processSingleCxt(IcePack pack) {
return cxts.get(0);
}

/*
/*
* 需要执行后的cxt列表
*
* @param pack 包裹
Expand Down
45 changes: 17 additions & 28 deletions ice-client/src/main/java/com/ice/client/config/IceClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,29 @@
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
* @author zjn
*/
@Configuration
@EnableConfigurationProperties(IceClientProperties.class)
public class IceClientConfig {

@Value("${ice.rabbit.host:}")
private String host;
@Value("${ice.rabbit.username:}")
private String username;
@Value("${ice.rabbit.password:}")
private String password;
@Value("${ice.rabbit.port:}")
private Integer port;

@Value("${ice.app:}")
private Integer app;
/*
* 等待初始化返回时间 默认10s
*/
@Value("${ice.init.reply.timeout:10000}")
private int timeout;
@Resource
private IceClientProperties properties;

@Bean(name = "iceConnectionFactory")
public ConnectionFactory iceConnectionFactory() {
CachingConnectionFactory iceConnectionFactory = new CachingConnectionFactory();
iceConnectionFactory.setUsername(username);
iceConnectionFactory.setPassword(password);
iceConnectionFactory.setHost(host);
iceConnectionFactory.setPort(port);
iceConnectionFactory.setUsername(properties.getRabbit().getUsername());
iceConnectionFactory.setPassword(properties.getRabbit().getPassword());
iceConnectionFactory.setHost(properties.getRabbit().getHost());
iceConnectionFactory.setPort(properties.getRabbit().getPort());
return iceConnectionFactory;
}

Expand All @@ -68,7 +57,7 @@ public DirectExchange iceUpdateExchange() {
public Binding iceUpdateBinding(
@Qualifier("iceUpdateQueue") Queue iceUpdateQueue,
@Qualifier("iceUpdateExchange") DirectExchange iceUpdateExchange) {
return BindingBuilder.bind(iceUpdateQueue).to(iceUpdateExchange).with(Constant.getUpdateRoutetKey(app));
return BindingBuilder.bind(iceUpdateQueue).to(iceUpdateExchange).with(Constant.getUpdateRoutetKey(properties.getApp()));
}

@Bean("iceUpdateMessageContainer")
Expand All @@ -88,7 +77,7 @@ public SimpleMessageListenerContainer iceUpdateMessageContainer(

@Bean(name = "iceShowConfQueue")
public Queue iceShowConfQueue() {
return QueueBuilder.nonDurable(Constant.getShowConfQueue(app)).autoDelete().build();
return QueueBuilder.nonDurable(Constant.getShowConfQueue(properties.getApp())).autoDelete().build();
}

@Bean(name = "iceShowConfExchange")
Expand All @@ -100,7 +89,7 @@ public DirectExchange iceShowConfExchange() {
public Binding iceShowConfBinding(
@Qualifier("iceShowConfQueue") Queue iceShowConfQueue,
@Qualifier("iceShowConfExchange") DirectExchange iceShowConfExchange) {
return BindingBuilder.bind(iceShowConfQueue).to(iceShowConfExchange).with(String.valueOf(app));
return BindingBuilder.bind(iceShowConfQueue).to(iceShowConfExchange).with(String.valueOf(properties.getApp()));
}

@Bean("iceShowConfMessageContainer")
Expand All @@ -114,13 +103,13 @@ public SimpleMessageListenerContainer iceShowConfMessageContainer(
container.setPrefetchCount(1);
container.setConcurrentConsumers(1);
container.setAcknowledgeMode(AcknowledgeMode.NONE);
container.setMessageListener(new IceShowConfListener(app, iceRabbitTemplate));
container.setMessageListener(new IceShowConfListener(properties.getApp(), iceRabbitTemplate));
return container;
}

@Bean(name = "iceMockQueue")
public Queue iceMockQueue() {
return QueueBuilder.nonDurable(Constant.getMockQueue(app)).autoDelete().build();
return QueueBuilder.nonDurable(Constant.getMockQueue(properties.getApp())).autoDelete().build();
}

@Bean(name = "iceMockExchange")
Expand All @@ -132,7 +121,7 @@ public DirectExchange iceMockExchange() {
public Binding iceMockBinding(
@Qualifier("iceMockQueue") Queue iceMockQueue,
@Qualifier("iceMockExchange") DirectExchange iceMockExchange) {
return BindingBuilder.bind(iceMockQueue).to(iceMockExchange).with(String.valueOf(app));
return BindingBuilder.bind(iceMockQueue).to(iceMockExchange).with(String.valueOf(properties.getApp()));
}

@Bean
Expand All @@ -157,7 +146,7 @@ public SimpleMessageListenerContainer iceMockMessageContainer(
@Bean(name = "iceRabbitTemplate")
public RabbitTemplate iceRabbitTemplate(@Qualifier("iceConnectionFactory") ConnectionFactory iceConnectionFactory) {
RabbitTemplate iceRabbitTemplate = new RabbitTemplate(iceConnectionFactory);
iceRabbitTemplate.setReplyTimeout(timeout);
iceRabbitTemplate.setReplyTimeout(properties.getRabbit().getReplyTimeout());
return iceRabbitTemplate;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.ice.client.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Data
@ConfigurationProperties(prefix = "ice")
public class IceClientProperties {
/*
* appId
*/
private Integer app;
/*
* rabbitMq配置
*/
private IceClientRabbitProperties rabbit = new IceClientRabbitProperties();

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class IceClientRabbitProperties{
private int port;
private String host;
private String username;
private String password;
private int replyTimeout = 10000;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.ice.client.listener;

import com.alibaba.fastjson.JSON;
import com.ice.client.config.IceClientProperties;
import com.ice.common.constant.Constant;
import com.ice.common.exception.IceException;
import com.ice.common.model.IceTransferDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
Expand All @@ -23,24 +23,24 @@
@DependsOn("iceBeanFactory")
public final class IceClientInit implements InitializingBean {

@Value("${ice.app}")
private Integer app;
@Resource
private IceClientProperties properties;

@Resource(name = "iceAmqpAdmin")
private AmqpAdmin iceAmqpAdmin;

@Resource(name = "iceRabbitTemplate")
private RabbitTemplate iceRabbitTemplate;

/*
/*
* 避免初始化与更新之间存在遗漏更新消息,此处先保证mq初始化完毕
* 初始化ice通过restTemplate远程调用server链接完成
*/
@Override
public void afterPropertiesSet() {
log.info("ice client init iceStart");

Object obj = iceRabbitTemplate.convertSendAndReceive(Constant.getInitExchange(), "", String.valueOf(app));
Object obj = iceRabbitTemplate.convertSendAndReceive(Constant.getInitExchange(), "", String.valueOf(properties.getApp()));
String json = (String) obj;
if (!StringUtils.isEmpty(json)) {
IceTransferDto infoDto = JSON.parseObject(json, IceTransferDto.class);
Expand All @@ -50,6 +50,6 @@ public void afterPropertiesSet() {
IceUpdateListener.initEnd(infoDto.getVersion());
return;
}
throw new IceException("ice init error maybe server is down app:" + app);
throw new IceException("ice init error maybe server is down app:" + properties.getApp());
}
}
4 changes: 2 additions & 2 deletions ice-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

<parent>
<groupId>com.waitmoon.ice</groupId>
<artifactId>ice-parent</artifactId>
<version>0.0.1</version>
<artifactId>ice</artifactId>
<version>0.0.4</version>
</parent>

<artifactId>ice-common</artifactId>
Expand Down
Loading

0 comments on commit c71f0a9

Please sign in to comment.