Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
RocketMQ-Bridge
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨培培
RocketMQ-Bridge
Commits
a3566ba8
Commit
a3566ba8
authored
Jul 09, 2018
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add files
parents
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
374 additions
and
0 deletions
+374
-0
pom.xml
pom.xml
+102
-0
distribution.xml
src/main/assembly/distribution.xml
+35
-0
ctl.sh
src/main/bin/ctl.sh
+60
-0
BridgeApplication.java
...n/java/cn/weixiuhui/rocketmqbridge/BridgeApplication.java
+79
-0
Http.java
src/main/java/cn/weixiuhui/rocketmqbridge/Http.java
+73
-0
conf.properties
src/main/resources/conf.properties
+9
-0
TestApplication.java
src/test/java/TestApplication.java
+16
-0
No files found.
pom.xml
0 → 100644
View file @
a3566ba8
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
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>
<groupId>
cn.weixiuhui.rocketmq-bridge
</groupId>
<artifactId>
rocketmq-bridge
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<build>
<plugins>
<plugin>
<artifactId>
maven-assembly-plugin
</artifactId>
<configuration>
<descriptors>
<descriptor>
src/main/assembly/distribution.xml
</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>
make-assembly
</id>
<phase>
package
</phase>
<goals>
<goal>
single
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
com.aliyun.openservices
</groupId>
<artifactId>
ons-client
</artifactId>
<version>
1.7.7.Final
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
jcl-over-slf4j
</artifactId>
<version>
1.7.7
</version>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
<version>
1.7.7
</version>
</dependency>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>
development
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<properties>
</properties>
</profile>
<profile>
<id>
test
</id>
<properties>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.12
</version>
<configuration>
<skipTests>
true
</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>
production
</id>
<properties>
</properties>
<build>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.12
</version>
<configuration>
<skipTests>
true
</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
\ No newline at end of file
src/main/assembly/distribution.xml
0 → 100644
View file @
a3566ba8
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns=
"http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"
>
<id>
distribution
</id>
<formats>
<format>
tar.gz
</format>
</formats>
<baseDirectory>
${project.artifactId}
</baseDirectory>
<fileSets>
<fileSet>
<directory>
src/main/resources
</directory>
<includes>
<include>
conf.properties
</include>
</includes>
<outputDirectory>
/conf
</outputDirectory>
<filtered>
true
</filtered>
</fileSet>
<fileSet>
<directory>
src/main/bin
</directory>
<includes>
<include>
*
</include>
</includes>
<outputDirectory>
/bin
</outputDirectory>
<fileMode>
0755
</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>
/lib
</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
\ No newline at end of file
src/main/bin/ctl.sh
0 → 100644
View file @
a3566ba8
#!/bin/bash
mainClass
=
cn.weixiuhui.rocketmqbridge.BridgeApplication
# resolve links - $0 may be a softlink
PRG
=
"
$0
"
while
[
-h
"
$PRG
"
]
;
do
ls
=
`
ls
-ld
"
$PRG
"
`
link
=
`
expr
"
$ls
"
:
'.*-> \(.*\)$'
`
if
expr
"
$link
"
:
'/.*'
>
/dev/null
;
then
PRG
=
"
$link
"
else
PRG
=
`
dirname
"
$PRG
"
`
/
"
$link
"
fi
done
# Get standard environment variables
PRGDIR
=
`
dirname
"
$PRG
"
`
PROJECT_DIR
=
`
cd
"
$PRGDIR
/.."
>
/dev/null
;
pwd
`
echo
PROJECT_DIR
=
$PROJECT_DIR
CLASSPATH
=
"
$CLASSHPATH
:
$PROJECT_DIR
/conf"
for
jar
in
"
$PROJECT_DIR
/lib"
/
*
.jar
;
do
CLASSPATH
=
"
$CLASSPATH
:
$jar
"
done
echo
CLASSPATH
=
$CLASSPATH
JVMARGS
=
"
${
JVMARGS
}
-Dproject_dir=
${
PROJECT_DIR
}
"
echo
JVMARGS
=
$JVMARGS
usage
()
{
echo
>
&2
"usage:
$PRG
<command> [args]"
echo
'Valid commands: start, stop'
exit
1
}
start
()
{
JAVA
=
${
JAVA
-
'java'
}
exec
$JAVA
$JVMARGS
-classpath
"
$CLASSPATH
"
$mainClass
"
$@
"
}
case
$1
in
(
start
)
shift
start
;;
(
stop
)
echo
"stop"
;;
(
restart
)
echo
"restart"
;;
(
*
)
echo
>
&2
"
$PRG
: error: unknown command '
$1
'"
usage
;;
esac
src/main/java/cn/weixiuhui/rocketmqbridge/BridgeApplication.java
0 → 100644
View file @
a3566ba8
package
cn
.
weixiuhui
.
rocketmqbridge
;
import
com.aliyun.openservices.ons.api.*
;
import
org.apache.log4j.BasicConfigurator
;
import
org.apache.log4j.Level
;
import
org.apache.log4j.Logger
;
import
java.io.IOException
;
import
java.util.Properties
;
/**
* Created by pader on 2018/7/5.
*/
public
class
BridgeApplication
{
public
static
void
main
(
String
[]
args
)
{
final
Logger
logger
=
getLogger
();
logger
.
info
(
"Read config."
);
Properties
ps
=
new
Properties
();
try
{
ps
.
load
(
BridgeApplication
.
class
.
getClassLoader
().
getResourceAsStream
(
"conf.properties"
));
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"Read config error: "
+
e
.
getMessage
());
return
;
}
String
accessKey
=
ps
.
getProperty
(
"rocketmq.accessKey"
);
String
secretKey
=
ps
.
getProperty
(
"rocketmq.secretKey"
);
String
onsAddr
=
ps
.
getProperty
(
"rocketmq.onsAddr"
);
String
consumerId
=
ps
.
getProperty
(
"consumer.id"
);
String
topic
=
ps
.
getProperty
(
"consumer.topic"
);
String
tag
=
ps
.
getProperty
(
"consumer.tag"
);
final
String
relayUrl
=
ps
.
getProperty
(
"consumer.relayUrl"
);
logger
.
info
(
"Create consumer: \""
+
consumerId
+
"\"."
);
Properties
props
=
new
Properties
();
// 您在控制台创建的 Consumer ID
props
.
put
(
PropertyKeyConst
.
ConsumerId
,
consumerId
);
props
.
put
(
PropertyKeyConst
.
AccessKey
,
accessKey
);
props
.
put
(
PropertyKeyConst
.
SecretKey
,
secretKey
);
props
.
put
(
PropertyKeyConst
.
ONSAddr
,
onsAddr
);
logger
.
info
(
"Subscribe topic: \""
+
topic
+
"\", tag: \""
+
tag
+
"\"."
);
Consumer
consumer
=
ONSFactory
.
createConsumer
(
props
);
consumer
.
subscribe
(
topic
,
tag
,
new
MessageListener
()
{
public
Action
consume
(
Message
message
,
ConsumeContext
context
)
{
String
body
=
new
String
(
message
.
getBody
());
logger
.
info
(
"Receive message: "
+
body
);
String
result
=
Http
.
sendPost
(
relayUrl
,
body
);
logger
.
info
(
"Post return: "
+
result
);
return
Action
.
CommitMessage
;
}
});
consumer
.
start
();
logger
.
info
(
"Consumer Started."
);
}
private
static
Logger
getLogger
()
{
Logger
logger
=
Logger
.
getLogger
(
BridgeApplication
.
class
);
BasicConfigurator
.
configure
();
//使用默认的配置信息,不需要写log4j.properties
logger
.
setLevel
(
Level
.
INFO
);
//设置日志输出级别为info,这将覆盖配置文件中设置的级别
return
logger
;
}
}
src/main/java/cn/weixiuhui/rocketmqbridge/Http.java
0 → 100644
View file @
a3566ba8
package
cn
.
weixiuhui
.
rocketmqbridge
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.PrintWriter
;
import
java.net.URL
;
import
java.net.URLConnection
;
/**
* Created by pader on 2018/7/7.
*/
public
class
Http
{
/**
* 向指定 URL 发送POST方法的请求
*
* @param url
* 发送请求的 URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public
static
String
sendPost
(
String
url
,
String
param
)
{
PrintWriter
out
=
null
;
BufferedReader
in
=
null
;
String
result
=
""
;
try
{
URL
realUrl
=
new
URL
(
url
);
// 打开和URL之间的连接
URLConnection
conn
=
realUrl
.
openConnection
();
// 设置通用的请求属性
conn
.
setRequestProperty
(
"Connection"
,
"Close"
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 发送请求参数
out
.
print
(
param
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
;
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送 POST 请求出现异常!"
+
e
);
e
.
printStackTrace
();
}
finally
{
//使用finally块来关闭输出流、输入流
try
{
if
(
out
!=
null
){
out
.
close
();
}
if
(
in
!=
null
){
in
.
close
();
}
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
}
return
result
;
}
}
src/main/resources/conf.properties
0 → 100644
View file @
a3566ba8
rocketmq.accessKey
=
LTAIdjHY84ZRSSVU
rocketmq.secretKey
=
s0Ak53bx5cPPQxpq4sD8qx04EwDCJe
rocketmq.onsAddr
=
http://onsaddr-internet.aliyun.com/rocketmq/nsaddr4client-internet
consumer.id
=
CID-wxh-portal-test
consumer.topic
=
wxh-order-operation-test
consumer.tag
=
workerFinish
consumer.relayUrl
=
http://u.yunya.com/api/order-consumer
\ No newline at end of file
src/test/java/TestApplication.java
0 → 100644
View file @
a3566ba8
import
cn.weixiuhui.rocketmqbridge.Http
;
/**
* Created by pader on 2018/7/7.
*/
public
class
TestApplication
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Start request."
);
String
result
=
Http
.
sendPost
(
"http://u.yunya.com/api/order-consumer"
,
"{\"finishTime\":1530947632960,\"workerId\":\"worker-71318\",\"orderId\":6091183}"
);
System
.
out
.
println
(
result
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment