Skip to content

Commit

Permalink
Merge c381783 into 064f29e
Browse files Browse the repository at this point in the history
  • Loading branch information
sonus21 committed Feb 27, 2020
2 parents 064f29e + c381783 commit c1b6dc1
Show file tree
Hide file tree
Showing 29 changed files with 516 additions and 414 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Expand Up @@ -22,7 +22,7 @@ allprojects {

subprojects {
group = 'com.github.sonus21'
version = '1.3-RELEASE'
version = '1.3.1-RELEASE'

dependencies {
// https://mvnrepository.com/artifact/org.springframework/spring-messaging
Expand All @@ -47,6 +47,12 @@ subprojects {
// https://mvnrepository.com/artifact/org.springframework/spring-test
testCompile group: 'org.springframework', name: 'spring-test', version: '5.2.0.RELEASE'
testCompile('org.springframework.boot:spring-boot-test:2.2.0.RELEASE')
// https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.5'

// https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.5'

configurations {
all*.exclude module: 'spring-boot-starter-logging'
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,13 +19,15 @@
import com.github.sonus21.rqueue.producer.RqueueMessageSender;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class Controller {
private RqueueMessageSender rqueueMessageSender;

Expand All @@ -51,6 +53,7 @@ public String sendJobNotification() {
job.setId(UUID.randomUUID().toString());
job.setMessage("Hi this is " + job.getId());
rqueueMessageSender.put("job-queue", job);
log.info("{}", job);
return job.toString();
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion rqueue-spring-boot-example/src/main/resources/logback.xml
Expand Up @@ -5,7 +5,7 @@
</encoder>
</appender>

<logger level="DEBUG" name="com.github.sonus21.rqueue.core">
<logger level="INFO" name="root">
<appender-ref ref="STDOUT"/>
</logger>
</configuration>
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package com.github.sonus21.rqueue.spring.boot;

import com.github.sonus21.rqueue.listener.RqueueMessageListenerContainer;
import com.github.sonus21.rqueue.metrics.QueueCounter;
import com.github.sonus21.rqueue.metrics.RqueueCounter;
import com.github.sonus21.rqueue.metrics.RqueueMetrics;
import io.micrometer.core.instrument.MeterRegistry;
Expand All @@ -36,7 +37,7 @@
@EnableConfigurationProperties(RqueueMetricsProperties.class)
public class RqueueMetricsAutoConfig {
@Bean
public RqueueCounter rqueueCounter(
public RqueueMetrics rqueueMetrics(
MetricsProperties metricsProperties,
MeterRegistry meterRegistry,
RqueueMessageListenerContainer rqueueMessageListenerContainer,
Expand All @@ -49,9 +50,16 @@ public RqueueCounter rqueueCounter(
actualTags = Tags.concat(actualTags, e.getKey(), e.getValue());
}
rqueueMetricsProperties.setMetricTags(actualTags);
RqueueCounter counter = new RqueueCounter();
RqueueMetrics.monitor(
rqueueMessageListenerContainer, meterRegistry, rqueueMetricsProperties, counter);
return counter;
QueueCounter queueCounter = new QueueCounter();
return new RqueueMetrics(
rqueueMessageListenerContainer.getRqueueMessageTemplate(),
rqueueMetricsProperties,
meterRegistry,
queueCounter);
}

@Bean
public RqueueCounter rqueueCounter(RqueueMetrics rqueueMetrics) {
return new RqueueCounter(rqueueMetrics.getQueueCounter());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,24 +16,31 @@

package com.github.sonus21.rqueue.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
* Checks whether MeterRegistry class is present it or not. if MeterRegistry class is founds then
* it's assumed that Metric feature is enables. It's essential to restrict the bean creation
* otherwise can lead to error in bootstrap process.
* Checks whether MeterRegistry bean is present it or not. if MeterRegistry bean is founds then it's
* assumed that Metric feature is enables. It's essential to restrict the bean creation otherwise
* can lead to error in bootstrap process.
*/
public class MetricsEnabled implements Condition {

@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
try {
Class.forName("io.micrometer.core.instrument.MeterRegistry");
} catch (ClassNotFoundException e) {
ConfigurableListableBeanFactory factory = context.getBeanFactory();
if (factory != null) {
factory.getBean(io.micrometer.core.instrument.MeterRegistry.class);
return true;
}
} catch (ClassNotFoundException | BeansException e) {
return false;
}
return true;
return false;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import com.github.sonus21.rqueue.config.RqueueConfig;
import com.github.sonus21.rqueue.listener.RqueueMessageHandler;
import com.github.sonus21.rqueue.listener.RqueueMessageListenerContainer;
import com.github.sonus21.rqueue.metrics.QueueCounter;
import com.github.sonus21.rqueue.metrics.RqueueCounter;
import com.github.sonus21.rqueue.metrics.RqueueMetrics;
import com.github.sonus21.rqueue.producer.RqueueMessageSender;
Expand Down Expand Up @@ -74,13 +75,21 @@ public RedisMessageListenerContainer redisMessageListenerContainer() {

@Bean
@Conditional(MetricsEnabled.class)
public RqueueCounter rqueueCounter(
public RqueueMetrics rqueueMetrics(
RqueueMessageListenerContainer rqueueMessageListenerContainer,
MeterRegistry meterRegistry,
RqueueMetricsProperties metricsProperties) {
RqueueCounter rqueueCounter = new RqueueCounter();
RqueueMetrics.monitor(
rqueueMessageListenerContainer, meterRegistry, metricsProperties, rqueueCounter);
return rqueueCounter;
RqueueMetricsProperties rqueueMetricsProperties) {
QueueCounter queueCounter = new QueueCounter();
return new RqueueMetrics(
rqueueMessageListenerContainer.getRqueueMessageTemplate(),
rqueueMetricsProperties,
meterRegistry,
queueCounter);
}

@Bean
@Conditional(MetricsEnabled.class)
public RqueueCounter rqueueCounter(RqueueMetrics rqueueMetrics) {
return new RqueueCounter(rqueueMetrics.getQueueCounter());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2019 Sonu Kumar
* Copyright 2020 Sonu Kumar
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit c1b6dc1

Please sign in to comment.