snow

common utils

License

License

GroupId

GroupId

vip.justlive
ArtifactId

ArtifactId

snow
Last Version

Last Version

1.1.2
Release Date

Release Date

Type

Type

pom
Description

Description

snow
common utils
Project URL

Project URL

https://github.com/justlive1/earth-snow
Source Code Management

Source Code Management

https://github.com/justlive1/earth-snow

Download snow

Filename Size
snow-1.1.2.pom 7 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/vip.justlive/snow/ -->
<dependency>
    <groupId>vip.justlive</groupId>
    <artifactId>snow</artifactId>
    <version>1.1.2</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/vip.justlive/snow/
implementation 'vip.justlive:snow:1.1.2'
// https://jarcasting.com/artifacts/vip.justlive/snow/
implementation ("vip.justlive:snow:1.1.2")
'vip.justlive:snow:pom:1.1.2'
<dependency org="vip.justlive" name="snow" rev="1.1.2">
  <artifact name="snow" type="pom" />
</dependency>
@Grapes(
@Grab(group='vip.justlive', module='snow', version='1.1.2')
)
libraryDependencies += "vip.justlive" % "snow" % "1.1.2"
[vip.justlive/snow "1.1.2"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • snow-common-base
  • snow-common-web
  • snow-common-web-vertx
  • snow-common-spring-rabbit

基础服务

介绍

  • snow-common-base J2SE基础
  • snow-common-web J2EE基础
  • snow-common-web-vertx Vertx Web扩展
  • snow-common-spring-rabbit spring-rabbit封装
  • 依赖方式
<dependency>
    <groupId>vip.justlive</groupId>
    <artifactId>snow-common-base</artifactId>
    <version>${snow.version}</version>
</dependency>

<dependency>
    <groupId>vip.justlive</groupId>
    <artifactId>snow-common-web</artifactId>
    <version>${snow.version}</version>
</dependency>

<dependency>
    <groupId>vip.justlive</groupId>
    <artifactId>snow-common-web-vertx</artifactId>
    <version>${snow.version}</version>
</dependency>

<dependency>
    <groupId>vip.justlive</groupId>
    <artifactId>snow-common-spring-rabbit</artifactId>
    <version>${snow.version}</version>
</dependency>

特性

  • 基于properties配置进行项目定制
  • 极简xml
  • 自动装载 依赖jar配置properties无需额外配置

开发

snow-common-base
	公共常量
	异常处理封装
	工具类
snow-common-web
	web异常处理封装
	webmvc基本组件配置提供
	用户相关工具类
	公共对外rest接口提供
	
snow-common-web-vertx
	扩展Route增加注解实现
	
snow-common-spring-rabbit
	spring-rabbit的封装

使用

Response返回

RestController返回使用vip.justlive.common.base.domain.Response进行包装

# 成功返回  成功编码 00000
Response.success(T t);
# 错误返回 默认错误码 99999
Response.error(String msg);
# 自定义错误编码
Response.error(String code, String msg);

异常处理

代码中需要throw异常时需要使用vip.justlive.common.base.exception.Exceptions进行包装,抛出CodedException

注意:

  • 异常尽量不要try catch
  • WebExceptionHandler统一处理了异常
# 构造ErrorCode
ErrorCode err = Exceptions.errorCode(String module, String code);
ErrorCode err = Exceptions.errorMessage(String module, String code, String message);

# 异常包装,抛出unchecked异常
throw Exceptions.wrap(Throwable e);
throw Exceptions.wrap(Throwable e, String code, String message);
throw Exceptions.wrap(Throwable e, ErrorCode errorCode, Object... arguments);

# 抛出业务逻辑异常,不含堆栈信息
throw Exceptions.fail(ErrorCode errCode, Object... params);
throw Exceptions.fail(String code, String message, Object... params);

# 故障型异常,包含堆栈信息
throw Exceptions.fault(ErrorCode errCode, Object... params);
throw Exceptions.fault(String code, String message, Object... params);
throw Exceptions.fault(Throwable e, ErrorCode errCode, Object... params);
throw Exceptions.fault(Throwable e, String code, String message, Object... params)

rabbit

依赖jar

<dependency>
    <groupId>vip.justlive</groupId>
    <artifactId>snow-common-spring-rabbit</artifactId>
    <version>${snow.version}</version>
</dependency>

生产者开发

  • 消息的发送方只需要写以下代码,就可以实现消息的发送
  • MessageProducer需要通过Spring注入
  • sendMessage方法,第一个参数是交换机名称,第二个参数是队列的名称,第三个参数是消息实体
  • sendMessageWithDelay方法,第一个参数是交换机名称,第二个参数是队列的名称,第三个参数是消息实体,第四个参数是延迟的时间,单位毫秒
  @Autowired
  MessageProducer producer;

  @Test
  public void testRabbit() throws IOException {
    Vo message = new Vo();
    message.setCode("12313");
    message.setDate(new Date());
    producer.sendMessage("e.sms", "q.sms", message);
  }

消费者开发

  • delay=true 是延迟消息 。使用延迟消息 ,务必加上此注解
  • 实现MessageProcess接口,在process方法体内做消息的业务处理
  • 加上@Rqueue注解,如果程序要消费多个不同的队列,那就再写多个这样的类,实现MessageProcess
  • 自动配置需要加上vip.justlive.common.spring.rabbit包的扫描
@Rqueue(queueName = "q.sms", exchangeName = "e.sms")
public class MessageProcessDemo implements MessageProcess<Vo> {

  @Override
  public void process(Vo message) {
    System.out.println("process message -> " + JSON.toJSON(message));
  }
}

Versions

Version
1.1.2
1.1.1
1.1.0
1.0.0