mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
update examples
This commit is contained in:
parent
beb00fbb10
commit
f3dea3a9dd
32
pom.xml
32
pom.xml
@ -74,6 +74,10 @@
|
|||||||
<javax-servlet-api>3.0</javax-servlet-api>
|
<javax-servlet-api>3.0</javax-servlet-api>
|
||||||
<slf4j-api.version>1.7.25</slf4j-api.version>
|
<slf4j-api.version>1.7.25</slf4j-api.version>
|
||||||
|
|
||||||
|
<!-- Apache Dubbo -->
|
||||||
|
<dubbo.version>2.7.3</dubbo.version>
|
||||||
|
<dubbo-spring-boot.version>2.7.3</dubbo-spring-boot.version>
|
||||||
|
|
||||||
<!-- Apache RocketMQ -->
|
<!-- Apache RocketMQ -->
|
||||||
<rocketmq.starter.version>2.0.2</rocketmq.starter.version>
|
<rocketmq.starter.version>2.0.2</rocketmq.starter.version>
|
||||||
|
|
||||||
@ -140,6 +144,34 @@
|
|||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Dubbo Spring Boot Starter -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.dubbo</groupId>
|
||||||
|
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||||
|
<version>${dubbo-spring-boot.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Dubbo -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.dubbo</groupId>
|
||||||
|
<artifactId>dubbo</artifactId>
|
||||||
|
<version>${dubbo.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-context</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>servlet-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.rocketmq</groupId>
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||||
|
@ -27,8 +27,6 @@
|
|||||||
<alicloud.context.version>1.0.5</alicloud.context.version>
|
<alicloud.context.version>1.0.5</alicloud.context.version>
|
||||||
<aliyun.sdk.edas.version>2.44.0</aliyun.sdk.edas.version>
|
<aliyun.sdk.edas.version>2.44.0</aliyun.sdk.edas.version>
|
||||||
<schedulerX.client.version>2.1.6</schedulerX.client.version>
|
<schedulerX.client.version>2.1.6</schedulerX.client.version>
|
||||||
<dubbo.version>2.7.3</dubbo.version>
|
|
||||||
<dubbo-spring-boot.version>2.7.1</dubbo-spring-boot.version>
|
|
||||||
<aliyun.java.sdk.dysmsapi>1.1.0</aliyun.java.sdk.dysmsapi>
|
<aliyun.java.sdk.dysmsapi>1.1.0</aliyun.java.sdk.dysmsapi>
|
||||||
<aliyun.sdk.mns>1.1.8.6</aliyun.sdk.mns>
|
<aliyun.sdk.mns>1.1.8.6</aliyun.sdk.mns>
|
||||||
<aliyun.java.sdk.dyvmsapi>1.1.1</aliyun.java.sdk.dyvmsapi>
|
<aliyun.java.sdk.dyvmsapi>1.1.1</aliyun.java.sdk.dyvmsapi>
|
||||||
@ -188,34 +186,6 @@
|
|||||||
<version>${seata.version}</version>
|
<version>${seata.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Dubbo Spring Boot Starter -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.dubbo</groupId>
|
|
||||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
|
||||||
<version>${dubbo-spring-boot.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Dubbo -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.dubbo</groupId>
|
|
||||||
<artifactId>dubbo</artifactId>
|
|
||||||
<version>${dubbo.version}</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-context</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>servlet-api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Aliyun OSS dependencies -->
|
<!-- Aliyun OSS dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
|
@ -281,7 +281,7 @@ NOTE: 该配置必须放在 bootstrap.properties 文件中。并且在添加配
|
|||||||
|
|
||||||
=== 支持自定义扩展的 Data Id 配置
|
=== 支持自定义扩展的 Data Id 配置
|
||||||
|
|
||||||
Nacos Config 从 0.2.1 版本后,可支持自定义 Data Id 的配置。关于这部分详细的设计可参考 https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/141[这里]。
|
Nacos Config 从 0.2.1 版本后,可支持自定义 Data Id 的配置。关于这部分详细的设计可参考 https://github.com/alibaba/spring-cloud-alibaba/issues/141[这里]。
|
||||||
一个完整的配置案例如下所示:
|
一个完整的配置案例如下所示:
|
||||||
|
|
||||||
[source,properties]
|
[source,properties]
|
||||||
|
@ -280,7 +280,7 @@ NOTE: This configuration must be in the bootstrap.properties file, and the value
|
|||||||
|
|
||||||
=== Support Custom Data Id
|
=== Support Custom Data Id
|
||||||
|
|
||||||
As of Spring Cloud Alibaba Nacos Config, data id can be self-defined. For detailed design of this part, refer to https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/141[Github issue].
|
As of Spring Cloud Alibaba Nacos Config, data id can be self-defined. For detailed design of this part, refer to https://github.com/alibaba/spring-cloud-alibaba/issues/141[Github issue].
|
||||||
The following is a complete sample:
|
The following is a complete sample:
|
||||||
|
|
||||||
[source,properties]
|
[source,properties]
|
||||||
|
@ -26,6 +26,7 @@ public class ConsumerApplication {
|
|||||||
|
|
||||||
@LoadBalanced
|
@LoadBalanced
|
||||||
@Bean
|
@Bean
|
||||||
|
@SentinelRestTemplate(urlCleanerClass = UrlCleaner.class, urlCleaner = "clean")
|
||||||
public RestTemplate restTemplate() {
|
public RestTemplate restTemplate() {
|
||||||
return new RestTemplate();
|
return new RestTemplate();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
||||||
|
|
||||||
|
public class UrlCleaner {
|
||||||
|
public static String clean(String url) {
|
||||||
|
System.out.println("enter urlCleaner");
|
||||||
|
if (url.matches(".*/echo/.*")) {
|
||||||
|
System.out.println("change url");
|
||||||
|
url = url.replaceAll("/echo/.*", "/echo/{str}");
|
||||||
|
}
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
spring.application.name=service-consumer-1X
|
spring.application.name=service-consumer-1X
|
||||||
server.port=18083
|
server.port=18083
|
||||||
management.security.enabled=false
|
management.security.enabled=false
|
||||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
#spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||||
|
spring.cloud.nacos.server-addr=127.0.0.1:8848
|
||||||
feign.sentinel.enabled=true
|
feign.sentinel.enabled=true
|
||||||
spring.cloud.sentinel.transport.dashboard=localhost:8080
|
spring.cloud.sentinel.transport.dashboard=localhost:8080
|
||||||
spring.cloud.sentinel.eager=true
|
spring.cloud.sentinel.eager=true
|
||||||
|
@ -1 +1,3 @@
|
|||||||
config: config-from-yml
|
config: config-from-yml
|
||||||
|
server:
|
||||||
|
port: 7777
|
@ -19,7 +19,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class OssApplication {
|
public class OssApplication {
|
||||||
|
|
||||||
public static final String BUCKET_NAME = "spring-cloud-alibaba-test";
|
public static final String BUCKET_NAME = "spring-cloud-alibaba";
|
||||||
|
|
||||||
public static void main(String[] args) throws URISyntaxException {
|
public static void main(String[] args) throws URISyntaxException {
|
||||||
SpringApplication.run(OssApplication.class, args);
|
SpringApplication.run(OssApplication.class, args);
|
||||||
|
@ -1,5 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import com.aliyun.oss.OSS;
|
import com.aliyun.oss.OSS;
|
||||||
@ -10,12 +28,13 @@ import org.apache.commons.codec.CharEncoding;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.WritableResource;
|
||||||
import org.springframework.util.StreamUtils;
|
import org.springframework.util.StreamUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OSS Controller
|
* OSS Controller.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||||
*/
|
*/
|
||||||
@ -25,8 +44,11 @@ public class OssController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private OSS ossClient;
|
private OSS ossClient;
|
||||||
|
|
||||||
|
@Value("classpath:/oss-test.json")
|
||||||
|
private Resource localFile;
|
||||||
|
|
||||||
@Value("oss://" + OssApplication.BUCKET_NAME + "/oss-test.json")
|
@Value("oss://" + OssApplication.BUCKET_NAME + "/oss-test.json")
|
||||||
private Resource file;
|
private Resource remoteFile;
|
||||||
|
|
||||||
@GetMapping("/upload")
|
@GetMapping("/upload")
|
||||||
public String upload() {
|
public String upload() {
|
||||||
@ -45,7 +67,7 @@ public class OssController {
|
|||||||
public String fileResource() {
|
public String fileResource() {
|
||||||
try {
|
try {
|
||||||
return "get file resource success. content: " + StreamUtils.copyToString(
|
return "get file resource success. content: " + StreamUtils.copyToString(
|
||||||
file.getInputStream(), Charset.forName(CharEncoding.UTF_8));
|
remoteFile.getInputStream(), Charset.forName(CharEncoding.UTF_8));
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -67,4 +89,20 @@ public class OssController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/upload2")
|
||||||
|
public String uploadWithOutputStream() {
|
||||||
|
try {
|
||||||
|
try (OutputStream outputStream = ((WritableResource) this.remoteFile)
|
||||||
|
.getOutputStream();
|
||||||
|
InputStream inputStream = localFile.getInputStream()) {
|
||||||
|
StreamUtils.copy(inputStream, outputStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
return "upload with outputStream failed";
|
||||||
|
}
|
||||||
|
return "upload success";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "spring-cloud-alibaba",
|
"name": "spring-cloud-alibaba",
|
||||||
"github": "https://github.com/spring-cloud-incubator/spring-cloud-alibaba",
|
"github": "https://github.com/alibaba/spring-cloud-alibaba",
|
||||||
"authors": ["Jim", "flystar32"],
|
"authors": ["Jim", "flystar32"],
|
||||||
"emails": ["fangjian0423@gmail.com", "flystar32@163.com"]
|
"emails": ["fangjian0423@gmail.com", "flystar32@163.com"]
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.handler.annotation.Payload;
|
import org.springframework.messaging.handler.annotation.Payload;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -10,10 +11,10 @@ import org.springframework.stereotype.Service;
|
|||||||
@Service
|
@Service
|
||||||
public class ReceiveService {
|
public class ReceiveService {
|
||||||
|
|
||||||
@StreamListener("input1")
|
@StreamListener("input1")
|
||||||
public void receiveInput1(String receiveMsg) {
|
public void receiveInput1(Message message) {
|
||||||
System.out.println("input1 receive: " + receiveMsg);
|
System.out.println("input1 receive: " + message.getPayload() + ", foo header: " + message.getHeaders().get("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@StreamListener("input2")
|
@StreamListener("input2")
|
||||||
public void receiveInput2(String receiveMsg) {
|
public void receiveInput2(String receiveMsg) {
|
||||||
|
@ -28,6 +28,7 @@ public class RocketMQConsumerApplication {
|
|||||||
|
|
||||||
@Input("input4")
|
@Input("input4")
|
||||||
SubscribableChannel input4();
|
SubscribableChannel input4();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -4,6 +4,7 @@ spring.cloud.stream.bindings.input1.destination=test-topic
|
|||||||
spring.cloud.stream.bindings.input1.content-type=text/plain
|
spring.cloud.stream.bindings.input1.content-type=text/plain
|
||||||
spring.cloud.stream.bindings.input1.group=test-group1
|
spring.cloud.stream.bindings.input1.group=test-group1
|
||||||
spring.cloud.stream.rocketmq.bindings.input1.consumer.orderly=true
|
spring.cloud.stream.rocketmq.bindings.input1.consumer.orderly=true
|
||||||
|
spring.cloud.stream.rocketmq.bindings.input1.consumer.trustedPackages=com.alibaba.cloud
|
||||||
|
|
||||||
spring.cloud.stream.bindings.input2.destination=test-topic
|
spring.cloud.stream.bindings.input2.destination=test-topic
|
||||||
spring.cloud.stream.bindings.input2.content-type=text/plain
|
spring.cloud.stream.bindings.input2.content-type=text/plain
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
||||||
|
|
||||||
|
import org.springframework.cloud.stream.binder.PartitionSelectorStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||||
|
*/
|
||||||
|
public class MyPartitionSelectorStrategy implements PartitionSelectorStrategy {
|
||||||
|
@Override
|
||||||
|
public int selectPartition(Object key, int partitionCount) {
|
||||||
|
System.out
|
||||||
|
.println("partition key: " + key + ", partitionCount: " + partitionCount);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||||
import org.springframework.cloud.stream.annotation.Output;
|
import org.springframework.cloud.stream.annotation.Output;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.integration.support.MessageBuilder;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,6 +26,10 @@ public class RocketMQProduceApplication {
|
|||||||
|
|
||||||
@Output("output2")
|
@Output("output2")
|
||||||
MessageChannel output2();
|
MessageChannel output2();
|
||||||
|
|
||||||
|
@Output("output3")
|
||||||
|
MessageChannel output3();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -32,7 +38,12 @@ public class RocketMQProduceApplication {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public CustomRunner customRunner() {
|
public CustomRunner customRunner() {
|
||||||
return new CustomRunner();
|
return new CustomRunner("output1");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CustomRunner customRunner2() {
|
||||||
|
return new CustomRunner("output3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -41,24 +52,46 @@ public class RocketMQProduceApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class CustomRunner implements CommandLineRunner {
|
public static class CustomRunner implements CommandLineRunner {
|
||||||
|
|
||||||
|
private final String bindingName;
|
||||||
|
|
||||||
|
public CustomRunner(String bindingName) {
|
||||||
|
this.bindingName = bindingName;
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SenderService senderService;
|
private SenderService senderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MySource mySource;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
int count = 5;
|
if (this.bindingName.equals("output1")) {
|
||||||
for (int index = 1; index <= count; index++) {
|
int count = 5;
|
||||||
String msgContent = "msg-" + index;
|
for (int index = 1; index <= count; index++) {
|
||||||
if (index % 3 == 0) {
|
String msgContent = "msg-" + index;
|
||||||
senderService.send(msgContent);
|
if (index % 3 == 0) {
|
||||||
}
|
senderService.send(msgContent);
|
||||||
else if (index % 3 == 1) {
|
}
|
||||||
senderService.sendWithTags(msgContent, "tagStr");
|
else if (index % 3 == 1) {
|
||||||
}
|
senderService.sendWithTags(msgContent, "tagStr");
|
||||||
else {
|
}
|
||||||
senderService.sendObject(new Foo(index, "foo"), "tagObj");
|
else {
|
||||||
|
senderService.sendObject(new Foo(index, "foo"), "tagObj");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (this.bindingName.equals("output3")) {
|
||||||
|
int count = 5;
|
||||||
|
for (int index = 1; index <= count; index++) {
|
||||||
|
String msgContent = "partitionMsg-" + index;
|
||||||
|
Message message = MessageBuilder.withPayload(msgContent)
|
||||||
|
.setHeader("myPartitionKey", "myPartitionKey").build();
|
||||||
|
mySource.output3().send(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ public class SenderService {
|
|||||||
public <T> void sendObject(T msg, String tag) throws Exception {
|
public <T> void sendObject(T msg, String tag) throws Exception {
|
||||||
Message message = MessageBuilder.withPayload(msg)
|
Message message = MessageBuilder.withPayload(msg)
|
||||||
.setHeader(MessageConst.PROPERTY_TAGS, tag)
|
.setHeader(MessageConst.PROPERTY_TAGS, tag)
|
||||||
|
.setHeader("foo", new Foo(1, "bar"))
|
||||||
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
|
.setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
|
||||||
.build();
|
.build();
|
||||||
source.output1().send(message);
|
source.output1().send(message);
|
||||||
|
@ -6,12 +6,20 @@ spring.cloud.stream.bindings.output1.destination=test-topic
|
|||||||
spring.cloud.stream.bindings.output1.content-type=application/json
|
spring.cloud.stream.bindings.output1.content-type=application/json
|
||||||
spring.cloud.stream.rocketmq.bindings.output1.producer.group=binder-group
|
spring.cloud.stream.rocketmq.bindings.output1.producer.group=binder-group
|
||||||
spring.cloud.stream.rocketmq.bindings.output1.producer.sync=true
|
spring.cloud.stream.rocketmq.bindings.output1.producer.sync=true
|
||||||
|
spring.cloud.stream.rocketmq.bindings.output1.producer.sendMessageTimeout=30000
|
||||||
|
|
||||||
spring.cloud.stream.bindings.output2.destination=TransactionTopic
|
spring.cloud.stream.bindings.output2.destination=TransactionTopic
|
||||||
spring.cloud.stream.bindings.output2.content-type=application/json
|
spring.cloud.stream.bindings.output2.content-type=application/json
|
||||||
spring.cloud.stream.rocketmq.bindings.output2.producer.transactional=true
|
spring.cloud.stream.rocketmq.bindings.output2.producer.transactional=true
|
||||||
spring.cloud.stream.rocketmq.bindings.output2.producer.group=myTxProducerGroup
|
spring.cloud.stream.rocketmq.bindings.output2.producer.group=myTxProducerGroup
|
||||||
|
|
||||||
|
spring.cloud.stream.bindings.output3.destination=partition-topic
|
||||||
|
spring.cloud.stream.bindings.output3.content-type=text/plain
|
||||||
|
spring.cloud.stream.bindings.output3.producer.partition-key-expression=headers['myPartitionKey']
|
||||||
|
spring.cloud.stream.bindings.output3.producer.partition-selector-class=com.alibaba.cloud.examples.MyPartitionSelectorStrategy
|
||||||
|
spring.cloud.stream.bindings.output3.producer.partition-count=8
|
||||||
|
spring.cloud.stream.rocketmq.bindings.output3.producer.group=partition-binder-group
|
||||||
|
|
||||||
spring.application.name=rocketmq-produce-example
|
spring.application.name=rocketmq-produce-example
|
||||||
|
|
||||||
server.port=28081
|
server.port=28081
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
import org.apache.dubbo.config.annotation.Reference;
|
import org.apache.dubbo.config.annotation.Reference;
|
||||||
@ -7,7 +23,9 @@ import org.apache.dubbo.config.annotation.Reference;
|
|||||||
*/
|
*/
|
||||||
public class FooServiceConsumer {
|
public class FooServiceConsumer {
|
||||||
|
|
||||||
@Reference(version = "${foo.service.version}", application = "${dubbo.application.id}", url = "dubbo://localhost:12345", timeout = 30000)
|
@Reference(version = "${foo.service.version}",
|
||||||
|
application = "${dubbo.application.id}",
|
||||||
|
url = "dubbo://localhost:12345?version=1.0.0", timeout = 30000)
|
||||||
private FooService fooService;
|
private FooService fooService;
|
||||||
|
|
||||||
public String hello(String name) {
|
public String hello(String name) {
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -34,8 +50,9 @@ public class SentinelDubboConsumerApp {
|
|||||||
FlowRuleManager.loadRules(Collections.singletonList(flowRule));
|
FlowRuleManager.loadRules(Collections.singletonList(flowRule));
|
||||||
|
|
||||||
SpringApplicationBuilder consumerBuilder = new SpringApplicationBuilder();
|
SpringApplicationBuilder consumerBuilder = new SpringApplicationBuilder();
|
||||||
ApplicationContext applicationContext = consumerBuilder.web(false)
|
ApplicationContext applicationContext = consumerBuilder
|
||||||
.sources(SentinelDubboConsumerApp.class).run(args);
|
.web(false).sources(SentinelDubboConsumerApp.class)
|
||||||
|
.run(args);
|
||||||
|
|
||||||
FooServiceConsumer service = applicationContext.getBean(FooServiceConsumer.class);
|
FooServiceConsumer service = applicationContext.getBean(FooServiceConsumer.class);
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
import org.apache.dubbo.config.annotation.Service;
|
import org.apache.dubbo.config.annotation.Service;
|
||||||
@ -5,11 +21,13 @@ import org.apache.dubbo.config.annotation.Service;
|
|||||||
/**
|
/**
|
||||||
* @author fangjian
|
* @author fangjian
|
||||||
*/
|
*/
|
||||||
@Service(version = "${foo.service.version}", application = "${dubbo.application.id}", protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}")
|
@Service(version = "${foo.service.version}", application = "${dubbo.application.id}",
|
||||||
|
protocol = "${dubbo.protocol.id}", registry = "${dubbo.registry.id}")
|
||||||
public class FooServiceImpl implements FooService {
|
public class FooServiceImpl implements FooService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String hello(String name) {
|
public String hello(String name) {
|
||||||
return "hello, " + name;
|
return "hello, " + name;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 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
|
||||||
|
*
|
||||||
|
* https://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 com.alibaba.cloud.examples;
|
package com.alibaba.cloud.examples;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
@ -13,8 +13,8 @@ spring:
|
|||||||
ruleType: gw-api-group
|
ruleType: gw-api-group
|
||||||
transport:
|
transport:
|
||||||
dashboard: localhost:8080
|
dashboard: localhost:8080
|
||||||
filter:
|
# filter:
|
||||||
enabled: false
|
# enabled: true
|
||||||
|
|
||||||
management.endpoints.web.exposure.include: "*"
|
management.endpoints.web.exposure.include: "*"
|
||||||
|
|
||||||
|
@ -91,6 +91,9 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
checkBlock4RestTemplate(sentinelRestTemplate.fallbackClass(),
|
checkBlock4RestTemplate(sentinelRestTemplate.fallbackClass(),
|
||||||
sentinelRestTemplate.fallback(), beanName,
|
sentinelRestTemplate.fallback(), beanName,
|
||||||
SentinelConstants.FALLBACK_TYPE);
|
SentinelConstants.FALLBACK_TYPE);
|
||||||
|
checkBlock4RestTemplate(sentinelRestTemplate.urlCleanerClass(),
|
||||||
|
sentinelRestTemplate.urlCleaner(), beanName,
|
||||||
|
SentinelConstants.URLCLEANER_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkBlock4RestTemplate(Class<?> blockClass, String blockMethod,
|
private void checkBlock4RestTemplate(Class<?> blockClass, String blockMethod,
|
||||||
|
@ -16,6 +16,11 @@
|
|||||||
|
|
||||||
package com.alibaba.alicloud.oss;
|
package com.alibaba.alicloud.oss;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.alibaba.alicloud.oss.resource.OssStorageProtocolResolver;
|
import com.alibaba.alicloud.oss.resource.OssStorageProtocolResolver;
|
||||||
|
|
||||||
import com.aliyun.oss.OSS;
|
import com.aliyun.oss.OSS;
|
||||||
@ -26,8 +31,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static com.alibaba.alicloud.oss.OssConstants.OSS_TASK_EXECUTOR_BEAN_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OSS Auto {@link Configuration}
|
* OSS Auto {@link Configuration}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||||
*/
|
*/
|
||||||
@ -42,4 +49,12 @@ public class OssAutoConfiguration {
|
|||||||
return new OssStorageProtocolResolver();
|
return new OssStorageProtocolResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean(name = OSS_TASK_EXECUTOR_BEAN_NAME)
|
||||||
|
@ConditionalOnMissingBean
|
||||||
|
public ExecutorService ossTaskExecutor() {
|
||||||
|
int coreSize = Runtime.getRuntime().availableProcessors();
|
||||||
|
return new ThreadPoolExecutor(coreSize, 128, 60, TimeUnit.SECONDS,
|
||||||
|
new LinkedBlockingQueue<Runnable>());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user