|
|
|
@ -56,7 +56,7 @@ public class SpringIntegrationMetricsIntegrationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void springIntegrationMetrics() { |
|
|
|
public void springIntegrationMetrics() { |
|
|
|
this.converter.fahrenheitToCelcius(68.0); |
|
|
|
this.converter.fahrenheitToCelsius(68.0); |
|
|
|
assertThat(this.registry.find("spring.integration.channel.sends") |
|
|
|
assertThat(this.registry.find("spring.integration.channel.sends") |
|
|
|
.tags("channel", "convert.input").value(Statistic.Count, 1).meter()) |
|
|
|
.tags("channel", "convert.input").value(Statistic.Count, 1).meter()) |
|
|
|
.isPresent(); |
|
|
|
.isPresent(); |
|
|
|
@ -98,7 +98,7 @@ public class SpringIntegrationMetricsIntegrationTests { |
|
|
|
return (f) -> f |
|
|
|
return (f) -> f |
|
|
|
.transform((payload) -> "{\"fahrenheit\":" + payload + "}", |
|
|
|
.transform((payload) -> "{\"fahrenheit\":" + payload + "}", |
|
|
|
(e) -> e.id("toJson")) |
|
|
|
(e) -> e.id("toJson")) |
|
|
|
.handle(String.class, this::fahrenheitToCelcius, |
|
|
|
.handle(String.class, this::fahrenheitToCelsius, |
|
|
|
(e) -> e.id("temperatureConverter")) |
|
|
|
(e) -> e.id("temperatureConverter")) |
|
|
|
.transform(this::extractResult, e -> e.id("toResponse")); |
|
|
|
.transform(this::extractResult, e -> e.id("toResponse")); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -106,19 +106,19 @@ public class SpringIntegrationMetricsIntegrationTests { |
|
|
|
private double extractResult(String json) { |
|
|
|
private double extractResult(String json) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return (double) new ObjectMapper().readValue(json, Map.class) |
|
|
|
return (double) new ObjectMapper().readValue(json, Map.class) |
|
|
|
.get("celcius"); |
|
|
|
.get("celsius"); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (IOException ex) { |
|
|
|
catch (IOException ex) { |
|
|
|
throw new RuntimeException(ex); |
|
|
|
throw new RuntimeException(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String fahrenheitToCelcius(String payload, Map<String, Object> headers) { |
|
|
|
private String fahrenheitToCelsius(String payload, Map<String, Object> headers) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
double fahrenheit = (double) new ObjectMapper() |
|
|
|
double fahrenheit = (double) new ObjectMapper() |
|
|
|
.readValue(payload, Map.class).get("fahrenheit"); |
|
|
|
.readValue(payload, Map.class).get("fahrenheit"); |
|
|
|
double celcius = (fahrenheit - 32) * (5.0 / 9.0); |
|
|
|
double celsius = (fahrenheit - 32) * (5.0 / 9.0); |
|
|
|
return "{\"celcius\":" + celcius + "}"; |
|
|
|
return "{\"celsius\":" + celsius + "}"; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) { |
|
|
|
catch (Exception ex) { |
|
|
|
throw new RuntimeException(ex); |
|
|
|
throw new RuntimeException(ex); |
|
|
|
@ -129,7 +129,7 @@ public class SpringIntegrationMetricsIntegrationTests { |
|
|
|
public interface TempConverter { |
|
|
|
public interface TempConverter { |
|
|
|
|
|
|
|
|
|
|
|
@Gateway(requestChannel = "convert.input") |
|
|
|
@Gateway(requestChannel = "convert.input") |
|
|
|
double fahrenheitToCelcius(double fahren); |
|
|
|
double fahrenheitToCelsius(double fahrenheit); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|