Skip to content

Commit 3c139a1

Browse files
author
gm2552
committed
Updating to SpringBoot 2.1.0.RELEASE
Adding load generator.
1 parent 6efdc05 commit 3c139a1

3 files changed

Lines changed: 56 additions & 11 deletions

File tree

pom.xml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<parent>
1919
<groupId>org.springframework.boot</groupId>
2020
<artifactId>spring-boot-starter-parent</artifactId>
21-
<version>2.1.0.RC1</version>
21+
<version>2.1.0.RELEASE</version>
2222
</parent>
2323
<developers>
2424
<developer>
@@ -47,21 +47,13 @@
4747
<name>Spring Milestone Releases</name>
4848
<url>https://repo.spring.io/milestone/</url>
4949
</repository>
50-
</repositories>
51-
<pluginRepositories>
52-
<!-- Temp repository for Spring Boot Milestone -->
53-
<pluginRepository>
54-
<id>spring-milestone</id>
55-
<name>Spring Milestone Releases</name>
56-
<url>https://repo.spring.io/milestone/</url>
57-
</pluginRepository>
58-
</pluginRepositories>
50+
</repositories>
5951
<dependencyManagement>
6052
<dependencies>
6153
<dependency>
6254
<groupId>org.springframework.boot</groupId>
6355
<artifactId>spring-boot-dependencies</artifactId>
64-
<version>2.1.0.RC1</version>
56+
<version>2.1.0.RELEASE</version>
6557
<type>pom</type>
6658
<scope>import</scope>
6759
</dependency>

src/main/java/org/nhindirect/smtpmq/gateway/boot/SmtpGatewayApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import org.springframework.boot.autoconfigure.SpringBootApplication;
88
import org.springframework.boot.builder.SpringApplicationBuilder;
99
import org.springframework.context.annotation.ComponentScan;
10+
import org.springframework.scheduling.annotation.EnableScheduling;
1011
import org.subethamail.smtp.server.SMTPServer;
1112

1213
@ComponentScan({"org.nhindirect.smtpmq.gateway"})
1314
@SpringBootApplication
15+
@EnableScheduling
1416
public class SmtpGatewayApplication implements CommandLineRunner
1517
{
1618
@Autowired
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.nhindirect.smtpmq.gateway.task;
2+
3+
import java.util.Arrays;
4+
import java.util.Calendar;
5+
6+
import javax.mail.Message;
7+
import javax.mail.Session;
8+
import javax.mail.internet.InternetAddress;
9+
import javax.mail.internet.MimeMessage;
10+
11+
import org.nhindirect.common.mail.SMTPMailMessage;
12+
import org.nhindirect.smtpmq.gateway.streams.SmtpGatewayMessageSource;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
15+
import org.springframework.beans.factory.annotation.Autowired;
16+
import org.springframework.beans.factory.annotation.Value;
17+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
18+
import org.springframework.scheduling.annotation.Scheduled;
19+
import org.springframework.stereotype.Component;
20+
21+
@ConditionalOnProperty(name="direct.smtpmqgateway.loadgen.rate", matchIfMissing=false)
22+
@Component
23+
public class SimulatedLoadTask
24+
{
25+
private static final Logger LOGGER = LoggerFactory.getLogger(SimulatedLoadTask.class);
26+
27+
@Value("${direct.smtpmqgateway.loadgen.sender}")
28+
protected String sender;
29+
30+
@Value("${direct.smtpmqgateway.loadgen.recipient}")
31+
protected String recipient;
32+
33+
@Autowired
34+
protected SmtpGatewayMessageSource msgSource;
35+
36+
@Scheduled(fixedRateString = "${direct.smtpmqgateway.loadgen.rate}", initialDelayString = "${direct.smtpmqgateway.loadgen.initialdelay:5000}")
37+
public void sendMessages() throws Exception
38+
{
39+
final MimeMessage msg = new MimeMessage((Session)null);
40+
msg.setFrom(new InternetAddress(sender));
41+
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
42+
msg.setSentDate(Calendar.getInstance().getTime());
43+
msg.setText("Load Test");
44+
45+
SMTPMailMessage smptMsg = new SMTPMailMessage(msg, Arrays.asList(new InternetAddress(recipient)), new InternetAddress(sender));
46+
47+
LOGGER.info("Sending generated load from " + sender + " to " + recipient);
48+
49+
msgSource.forwardSMTPMessage(smptMsg);
50+
}
51+
}

0 commit comments

Comments
 (0)