Skip to content

Commit

Permalink
Merge pull request #184 from starsys-tech/master
Browse files Browse the repository at this point in the history
Add support for rocketmq.
  • Loading branch information
gudaoxuri authored Jan 6, 2022
2 parents 002e1bb + 282afe3 commit b1fa558
Show file tree
Hide file tree
Showing 17 changed files with 715 additions and 0 deletions.
4 changes: 4 additions & 0 deletions examples/cluster-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-spi-redis</artifactId>
</dependency>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-spi-rocket</artifactId>
</dependency>
<!--<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-spi-hazelcast</artifactId>
Expand Down
65 changes: 65 additions & 0 deletions framework/modules/cluster-rocket/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2021. the original author or authors.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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>group.idealworld.dew</groupId>
<artifactId>parent-starter</artifactId>
<version>3.0.0-Beta3</version>
<relativePath>../parent-starter</relativePath>
</parent>

<artifactId>cluster-spi-rocket</artifactId>
<name>1.1.4 Dew Cluster Rocket</name>
<description>Dew 集群 Rocket 实现</description>
<packaging>jar</packaging>

<properties>
</properties>

<dependencies>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-common</artifactId>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId>
<version>${rocket.version}</version>
</dependency>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>cluster-common-test</artifactId>
</dependency>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>test-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>group.idealworld.dew</groupId>
<artifactId>test-starter</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2020. the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package group.idealworld.dew.core.cluster.spi.rocket;


import java.util.Map;

@FunctionalInterface
public interface ReceiveBeforeFun {


Object invoke(String topic, Map<String,Object> properties);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2020. the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package group.idealworld.dew.core.cluster.spi.rocket;


@FunctionalInterface
public interface ReceiveErrorFun {

/**
* Invoke.
*
* @param ex the ex
* @param beforeResult the before result
*/
void invoke(Exception ex, Object beforeResult);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2020. the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package group.idealworld.dew.core.cluster.spi.rocket;


@FunctionalInterface
public interface ReceiveFinishFun {

/**
* Invoke.
*
* @param beforeResult the before result
*/
void invoke(Object beforeResult);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2020. the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package group.idealworld.dew.core.cluster.spi.rocket;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.spring.core.RocketMQTemplate;

/**
* Rocket adapter.
*
* @author nipeixuan
*/
public class RocketAdapter {

private RocketMQTemplate rocketMQTemplate;

/**
* Instantiates a new Rabbit adapter.
*
* @param rocketMQTemplate the rabbit template
*/
public RocketAdapter(RocketMQTemplate rocketMQTemplate) {
this.rocketMQTemplate = rocketMQTemplate;
}

DefaultMQProducer getProducer(){
return rocketMQTemplate.getProducer();
}

RocketMQTemplate getRocketMQTemplate(){
return this.rocketMQTemplate;
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2020. the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package group.idealworld.dew.core.cluster.spi.rocket;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.validation.Valid;

/**
* rocket auto configuration.
*
* @author nipeixuan
*/
@Configuration
@ConditionalOnClass(RocketMQTemplate.class)
@ConditionalOnExpression("#{'${dew.cluster.mq}'=='rocket'}")
public class RocketAutoConfiguration {

private static final Logger logger = LoggerFactory.getLogger(RocketAutoConfiguration.class);

@Value("${rocketmq.producer.group}")
private String groupName;

@Value("${rocketmq.name-server}")
private String nameServer;


@PostConstruct
public void init() {
logger.info("Load Auto Configuration : {}", this.getClass().getName());
}

/**
* Rabbit adapter.
*
* @param rocketMQTemplate the rocket template
* @return the rocket adapter
*/
@Bean
public RocketAdapter rocketAdapter(RocketMQTemplate rocketMQTemplate) {
return new RocketAdapter(rocketMQTemplate);
}

/**
* Rocket cluster mq.
*
* @param rocketAdapter the rocket adapter
* @return the rocket cluster mq
*/
@Bean
@ConditionalOnExpression("'${dew.cluster.mq}'=='rocket'")
public RocketClusterMQ rocketClusterMQ(RocketAdapter rocketAdapter) {
return new RocketClusterMQ(rocketAdapter, nameServer, groupName);
}

}
Loading

0 comments on commit b1fa558

Please sign in to comment.