Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b026b13c
Commit
b026b13c
authored
May 10, 2014
by
Christian Dupuis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add HealthIndicator for Rabbit
parent
dac03fdb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
161 additions
and
2 deletions
+161
-2
pom.xml
spring-boot-actuator/pom.xml
+5
-0
HealthIndicatorAutoConfiguration.java
...tuate/autoconfigure/HealthIndicatorAutoConfiguration.java
+30
-2
RabbitHealthIndicator.java
...gframework/boot/actuate/health/RabbitHealthIndicator.java
+67
-0
RabbitHealthIndicatorTests.java
...ework/boot/actuate/health/RabbitHealthIndicatorTests.java
+59
-0
No files found.
spring-boot-actuator/pom.xml
View file @
b026b13c
...
@@ -111,6 +111,11 @@
...
@@ -111,6 +111,11 @@
<artifactId>
jedis
</artifactId>
<artifactId>
jedis
</artifactId>
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.amqp
</groupId>
<artifactId>
spring-rabbit
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- Test -->
<!-- Test -->
<dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<groupId>
ch.qos.logback
</groupId>
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java
View file @
b026b13c
...
@@ -20,15 +20,18 @@ import java.util.Map;
...
@@ -20,15 +20,18 @@ import java.util.Map;
import
javax.sql.DataSource
;
import
javax.sql.DataSource
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.health.CompositeHealthIndicator
;
import
org.springframework.boot.actuate.health.CompositeHealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.HealthIndicator
;
import
org.springframework.boot.actuate.health.MongoHealthIndicator
;
import
org.springframework.boot.actuate.health.MongoHealthIndicator
;
import
org.springframework.boot.actuate.health.RabbitHealthIndicator
;
import
org.springframework.boot.actuate.health.RedisHealthIndicator
;
import
org.springframework.boot.actuate.health.RedisHealthIndicator
;
import
org.springframework.boot.actuate.health.SimpleDataSourceHealthIndicator
;
import
org.springframework.boot.actuate.health.SimpleDataSourceHealthIndicator
;
import
org.springframework.boot.actuate.health.VanillaHealthIndicator
;
import
org.springframework.boot.actuate.health.VanillaHealthIndicator
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.jdbc.CommonsDataSourceConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.CommonsDataSourceConfiguration
;
...
@@ -46,7 +49,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
...
@@ -46,7 +49,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
/**
* {@link EnableAutoConfiguration Auto-configuration} for {@link HealthIndicator}s.
* {@link EnableAutoConfiguration Auto-configuration} for {@link HealthIndicator}s.
*
*
* @author Christian Dupuis
* @author Christian Dupuis
* @since 1.1.0
* @since 1.1.0
*/
*/
...
@@ -55,7 +58,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
...
@@ -55,7 +58,7 @@ import org.springframework.data.redis.connection.RedisConnectionFactory;
EmbeddedDataSourceConfiguration
.
class
,
CommonsDataSourceConfiguration
.
class
,
EmbeddedDataSourceConfiguration
.
class
,
CommonsDataSourceConfiguration
.
class
,
HikariDataSourceConfiguration
.
class
,
TomcatDataSourceConfiguration
.
class
,
HikariDataSourceConfiguration
.
class
,
TomcatDataSourceConfiguration
.
class
,
MongoAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
MongoAutoConfiguration
.
class
,
MongoDataAutoConfiguration
.
class
,
RedisAutoConfiguration
.
class
})
RedisAutoConfiguration
.
class
,
RabbitAutoConfiguration
.
class
})
public
class
HealthIndicatorAutoConfiguration
{
public
class
HealthIndicatorAutoConfiguration
{
@Bean
@Bean
...
@@ -137,4 +140,29 @@ public class HealthIndicatorAutoConfiguration {
...
@@ -137,4 +140,29 @@ public class HealthIndicatorAutoConfiguration {
}
}
}
}
@Configuration
@ConditionalOnBean
(
RabbitTemplate
.
class
)
public
static
class
RabbitHealthIndicatorConfiguration
{
@Autowired
private
Map
<
String
,
RabbitTemplate
>
rabbitTemplates
;
@Bean
@ConditionalOnMissingBean
(
name
=
"rabbitHealthIndicator"
)
public
HealthIndicator
<?>
redisHealthIndicator
()
{
if
(
this
.
rabbitTemplates
.
size
()
==
1
)
{
return
new
RabbitHealthIndicator
(
this
.
rabbitTemplates
.
values
().
iterator
()
.
next
());
}
CompositeHealthIndicator
composite
=
new
CompositeHealthIndicator
();
for
(
Map
.
Entry
<
String
,
RabbitTemplate
>
entry
:
this
.
rabbitTemplates
.
entrySet
())
{
composite
.
addHealthIndicator
(
entry
.
getKey
(),
new
RabbitHealthIndicator
(
entry
.
getValue
()));
}
return
composite
;
}
}
}
}
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/RabbitHealthIndicator.java
0 → 100644
View file @
b026b13c
/*
* Copyright 2012-2014 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
org
.
springframework
.
boot
.
actuate
.
health
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.amqp.rabbit.core.ChannelCallback
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.util.Assert
;
import
com.rabbitmq.client.Channel
;
/**
* Simple implementation of a {@link HealthIndicator} returning status information for the
* RabbitMQ messaging system.
*
* @author Christian Dupuis
* @since 1.1.0
*/
public
class
RabbitHealthIndicator
implements
HealthIndicator
<
Map
<
String
,
Object
>>
{
private
final
RabbitTemplate
rabbitTemplate
;
public
RabbitHealthIndicator
(
RabbitTemplate
rabbitTemplate
)
{
Assert
.
notNull
(
rabbitTemplate
,
"RabbitTemplate must not be null."
);
this
.
rabbitTemplate
=
rabbitTemplate
;
}
@Override
public
Map
<
String
,
Object
>
health
()
{
Map
<
String
,
Object
>
health
=
new
HashMap
<
String
,
Object
>();
try
{
health
.
put
(
"version"
,
this
.
rabbitTemplate
.
execute
(
new
ChannelCallback
<
String
>()
{
@Override
public
String
doInRabbit
(
Channel
channel
)
throws
Exception
{
Map
<
String
,
Object
>
serverProperties
=
channel
.
getConnection
().
getServerProperties
();
return
serverProperties
.
get
(
"version"
).
toString
();
}
}));
health
.
put
(
"status"
,
"ok"
);
}
catch
(
Exception
ex
)
{
health
.
put
(
"status"
,
"error"
);
health
.
put
(
"error"
,
ex
.
getClass
().
getName
()
+
": "
+
ex
.
getMessage
());
}
return
health
;
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/health/RabbitHealthIndicatorTests.java
0 → 100644
View file @
b026b13c
/*
* Copyright 2014 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
org
.
springframework
.
boot
.
actuate
.
health
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.amqp.rabbit.core.RabbitAdmin
;
import
org.springframework.boot.actuate.autoconfigure.EndpointAutoConfiguration
;
import
org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
* Tests for {@link RabbitHealthIndicator}.
*
* @author Christian Dupuis
*/
public
class
RabbitHealthIndicatorTests
{
private
AnnotationConfigApplicationContext
context
;
@After
public
void
close
()
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
}
}
@Test
public
void
indicatorExists
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
(
PropertyPlaceholderAutoConfiguration
.
class
,
RabbitAutoConfiguration
.
class
,
EndpointAutoConfiguration
.
class
,
HealthIndicatorAutoConfiguration
.
class
);
assertEquals
(
1
,
this
.
context
.
getBeanNamesForType
(
RabbitAdmin
.
class
).
length
);
RabbitHealthIndicator
healthIndicator
=
this
.
context
.
getBean
(
RabbitHealthIndicator
.
class
);
assertNotNull
(
healthIndicator
);
}
}
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