Spring Cloud Task not started with Spring Cloud Stream using RabbitMQ - rabbitmq

I am experimenting with Spring Cloud APIs as part of microservices course.
To setup server-less task, I am using Cloud Task, Cloud Stream(RabbitMQ), and Spring Web.
For this I have setup following projects:
Serverless task to be executed -
https://github.com/Omkar-Shetkar/pluralsight-springcloud-m3-task
Component to receive Http request from user and submit to RabbitMQ -
https://github.com/Omkar-Shetkar/pluralsight-springcloud-m3-taskintake
Sink component to receive TaskLaunchRequest and forward to cloud task - https://github.com/Omkar-Shetkar/pluralsight-springcloud-m3-tasksink
Having setup above components, ensured that task component is available in local maven repository.
After initiating a POST request onto /tasks in pluralsight.com.TaskController.launchTask(String) I see a HTTP response.
But, I couldn't see any update in tasklogs DB associated with serverless task.
This means, task it self is not called.
In RabbitMQ console I could see connections are established from intake and sink components but I don't see any message exchange happening.
Queue with name tasktopic is having ZERO message count.
Appreciate any pointers and suggestions on how to proceed on this to resolve this issue.
Thanks.

There were two issue with my current implementation:
In intake and sink modules -> application.properties, binding property key was wrong.
It should be:
In intake module
spring.cloud.stream.bindings.output.destination=tasktopic
In sink module
spring.cloud.stream.bindings.input.destination=tasktopic
Also, local cloud deployer versions were incompatible in sink modules pom.xml.
Updated the same to:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-deployer-local</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
With these changes, I am able to get RabbitMQ messages.

#EnableTaskLauncher annotation is missing in TaskIntakeApplication.
#SpringBootApplication
#EnableTaskLauncher
public class PluralsightSpringcloudM3TaskintakeApplication {
public static void main(String[] args) {
SpringApplication.run(PluralsightSpringcloudM3TaskintakeApplication.class, args);
}
}

Related

Spring Cloud Sleuth Traces w/ Gradle not showing up in Zipkin

I have a Spring Cloud Sleuth + Stream app working and sending to my local OpenZipkin (docker) when the app uses maven, however when I try to run an gradle spring boot app then Zipkin doesn't display the traces. The interesting thing is that the Spring logs seem to show the proper trace information..so the app itself is recognizing Sleuth but for some reason Zipkin either isn't receiving the info or it's not displaying. I went into the zipkin container and can't find any logs. How can this be troubleshot? Is there something that needs to be set when using gradle that isn't needed with maven?
Config info:
In the build.gradle file I have included sleuth as so:
implementation 'org.springframework.cloud:spring-cloud-starter-sleuth'
Version info:
set('springCloudVersion', "2020.0.4")
id 'org.springframework.boot' version '2.5.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
The only thing I am configuring in my application.yaml is below and it's the same in both the gradle and maven app. So I'm not pointing to some other address for zipkin or anything like that:
spring:
application:
name: OrchestratorService
sleuth:
sampler:
probability: 1.0
And app logs recognize Sleuth and include the app name, and trace info in each log entry, for example:
[2m2021-10-06 10:42:22.508[0;39m [32m INFO [OrchestratorService,9b22b40072a8931c,3f954b3ab81e4e7d][0;39m [35m21261[0;39m [2m---[0;39m [2m[pool-6-thread-1][0;39m [36ms.s.d.f.O.OrchestratorServiceApplication[0;39m [2m:[0;39m No further outbound event for card block service required. (No fraud was detected.)
Please do as the docs says:
Use spring-cloud-starter-sleuth which should add Sleuth support with log correlation and spring-cloud-sleuth-zipkin if you also want to send spans to Zipkin.
Here's an example from the docs: https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/htmlsingle/#how-to-set-up-sleuth-with-brave-zipkin-http
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}"
}
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-sleuth"
implementation "org.springframework.cloud:spring-cloud-sleuth-zipkin"
}

Error creating bean named `conversionServicePostProcessor` when using spring-boot-admin-server

I was trying to enable Spring boot admin server for my application. The default settings work perfectly fine but when I attempt to enable security, I am getting following error:
APPLICATION FAILED TO START
Description:
The bean 'conversionServicePostProcessor', defined in class path
resource
[org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class],
could not be registered. A bean with that name has already been
defined in class path resource
[org/springframework/security/config/annotation/web/reactive/WebFluxSecurityConfiguration.class]
and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting
spring.main.allow-bean-definition-overriding=true
Process finished with exit code 1
I am using the latest SNAPSHOT version of spring-boot-admin-starter-server (2.2.0-SNAPSHOT). Here is my security configuration:
#EnableAdminServer
#EnableWebFluxSecurity
#Configuration(proxyBeanMethods = false)
class AdminServerSecurityConfigurations(val adminServerProperties: AdminServerProperties) {
#Bean
fun adminServerSecurityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain = http
// #formatter:off
.authorizeExchange()
.pathMatchers("${adminServerProperties.contextPath}/assets/**").permitAll()
.pathMatchers("${adminServerProperties.contextPath}/login").permitAll()
.anyExchange().authenticated().and()
.formLogin().loginPage("${adminServerProperties.contextPath}/login").and()
.logout().logoutUrl("${adminServerProperties.contextPath}/logout").and()
.httpBasic().and()
// #formatter:on
.csrf().disable()
.build()
#Bean
fun notifyLogger(instanceRepository: InstanceRepository) = LoggingNotifier(instanceRepository)
}
I found a pull request to update the documentation: https://github.com/spring-projects/spring-boot/issues/14069
For Reactive WebSockets,
{spring-reference}web-reactive.html#webflux-websocket[Spring WebFlux] offers rich support,
which is accessible through the spring-boot-starter-webflux module.
See the spring-boot-sample-websocket-reactive sample project to see how WebSockets may
be implemented using Spring WebFlux.
it turns out that using webflux and websocket leads to conflicts.
also in this pull request was denied in the resolution of the conflict
https://github.com/spring-projects/spring-boot/issues/14810
for reactive websocket see this sample https://www.baeldung.com/spring-5-reactive-websockets
I had the same issue and was able solve it by adding
spring.main.allow-bean-definition-overriding=true
to my application.properties.
Sounds like a workaround and it was also only necessary if I deployed it as WAR -- as a standalone application the exception never occured.
I also faced this error, after Reimport All Mavne Projects(Intellij IDE) it works fine for me. Here my detailed input on this issue here

No component found with scheme : jetty

So I scoured the message boards and see some people that have bumped into this issue but usually it was due to a missing dependency in the POM file.
My case:
Running JBoss Fuse jboss-fuse-6.1.0.redhat-379
Apache Camel 2.14.1
Spring 3.2.8_RELEASE_1
Have the camel-jetty dependency in my POM file
Installed the feature in Karaf. Verified the feature is there in
OSGI list and feature list.
jetty / 8.1.14.v20131031
Runs fine within eclipse.
So I have a context with the following rest configuration:
<camelContext id="FIRST-CAMEL-CONTEXT" xmlns="http://camel.apache.org/schema/spring" streamCache="true">
<restConfiguration component="jetty" bindingMode="json" port="8881" host="0.0.0.0">
<dataFormatProperty key="prettyPrint" value="true"/>
</restConfiguration>
<rest path="/search" consumes="application/json" produces="application/json">
<description>Get Search Results</description>
<!-- this is a rest GET to find all users -->
<post uri="/SearchHotels" outType="HotelsEnvelope.Response" type="HotelsEnvelope.Request">
<description>Hotels</description>
<to uri="bean:searchRequest?method=ReturnHotels(Exchange,${body},${headers})"/>
</post>
</rest>
.....
</camelContext>
the beans defined above as such:
<bean id="searchRequest" class="ICEPricelineSVC.SearchRequest" />
In the Bean I basically create a context and then send a request to a third party service like so:
CamelContext context = new DefaultCamelContext();
ProducerTemplate template = context.createProducerTemplate();
.....
String url = String.format("jetty:http://api.rezserver.com/api/hotel/getResultsWithCacheV2?function_type=get&format=xml&refid=%s&api_key=%s&currency=USD&latitude=%s&longitude=%s&radius=%s&check_in=%s&check_out=%s&adults=2&children=0&rooms=1&nearby=0&recent=0&promo=1&sort_by=most_popular&sort_order=ASC&limit=5000&offset=0&format=xml&function_type=get&poi_name=search&bridgeEndpoint=true&amp;throwExceptionOnFailure=false",supplier.getCredentials().getRefid(),supplier.getCredentials().getKey(), request.getQryLocation().getLat().toString(), request.getQryLocation().getLng().toString(), request.getQryLocation().getRadius().toString(),formatter1.format(dateCheckIn), formatter1.format(dateCheckOut));
Exchange exchange = template.send(url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
Inits.setupDestinationURL(inMessage);
// set the operation name
inMessage.setHeader(Exchange.HTTP_METHOD, org.apache.camel.component.http4.HttpMethods.GET);
}
});
.....
When the producer template sends I get the jetty error.
I have tried various things. One of which is injecting the ApplicationContext in the bean and getting the FIRST_CAMEL_CONTEXT bean to retrieve the context. In that case the request seems to be sent but the exchange returned from the processor is null.
Again, this all works in eclipse. I also noticed that when I deploy the bundle I see it adding the dependencies to the container. Is there a good way to chase this? I have resorted to using the HTPClient for now but would really like to understand why there seems to be a classpath issue when using the producer.
Thanks.
JBoss Fuse 6.1 comes with Apache Camel 2.12.x out of the box. You must use that version as that is the certified and tested version.
JBoss Fuse 6.2 which is the next release comes with Apache Camel 2.14.x and that release has the new rest-dsl.

Mule DevKit Connectors, Connection Management and reconnect policies

Should a custom Mule connector written using the DevKit be compatible by default with reconnection policies. e.g., I wrote a connector using connection management following http://www.mulesoft.org/documentation/display/current/Implementing+Connection+Management
When I set up an error condition and my #Connect method throws a ConnectionException my flow stops and the connector doesn't try to reconnect despite having a global config element:
<configuration>
<reconnect-forever frequency="2000"/>
</configuration>
I know this config is working because it has the expected effect on a JDBC transport but not on my custom connector.
Am I missing something fundamental? Should custom connectors work at all with reconnect-forever policies?
I'm using Mule 3.4 CE and DevKit 3.4
Thanks for any help or pointers in the right direction.
In DevKit, in order for your operations to trigger the reconnection mechanism you need to mark the processor with the #ReconnectOn annotation, and specify the exception that will trigger the reconnection.
#Processor
#ReconnectOn(exceptions = {TypeAException.class, TypeBException.class})
public boolean fooProcessor(String param)
throws TypeAException, TypeBException, TypeCException;
In this example the exception of TypeCException will not trigger the reconnection, the others will.
If your #ValidateConnection method returns true, the #Connect won't be called again.

WebSphere MQ 6.0: Can't switch from non-durable to durable

When I switch from non-durable to durable topic subscriber, I am unable to look up the topic name that I could read before (using JNDI).
It gives an error in the admin console as the topic is being looked up:
An error occurred during activation of changes, please see the log for details.
ERROR: Could not activate itft-jmsmodule!ITFT-JMS-1#ItftTopic
The Messaging Kernel ITFT-JMS-1 has not yet been opened
I am using Oracle WebLogic Server Administrative Console to set up the WebSphere queue. On the console, I made these changes:
For the Persistent Stores, On the Configuration tab, Added a file store called ItftFileStore
For the Persistent Stores, On the Configuration tab, Added a directory.
For the JMS Servers, On the Configuration -> General tab, Changed the Persistent Store to ItftFileStore
For the JMS Servers, On the Configuration -> General tab -> Advanced, Checked the Store Enabled field.
For the ItftTopic, Configuration -> Override tab, Changed Delivery Mode Override to Persistent.
This is the code which I am running. There are some comments on the pertinent lines.
public void start() throws Exception {
try {
LOG.info("Starting the FC MQ message consumer / listener ...");
InitialContext initialContext = getInitialContext();
topicConnectionFactory = (TopicConnectionFactory) initialContext.lookup(jmsFactory);
topicConnection = topicConnectionFactory.createTopicConnection();
topicConnection.setClientID(clientId);
LOG.info("1"+topicConnection.getClientID());
topicSession = topicConnection.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
LOG.info("2"+topicConnection.getClientID());
//topicConnection.setExceptionListener(connectionExceptionListener);
jmsTopic = (Topic) initialContext.lookup(topic); // Error being thrown here
LOG.info("3"+topicConnection.getClientID());
//topicSubscriber = topicSession.createSubscriber(jmsTopic); // Works as a non-durable subscriber
topicSession.createDurableSubscriber(jmsTopic,subscriberName);
LOG.info("4"+topicConnection.getClientID());
topicSubscriber.setMessageListener(messageListener);
topicConnection.start();
The fundamental aspect of the problem is that you are connecting WebLogic to a Websphere JMS topic, this has become clear with the last edit of your question but it is not clear whether you are using WebLogic Messaging Bridge or not. The Messaging Bridge is the proper way of configuring a foreign JMS server in WebLogic. I suggest reading this FAQ and this how-to that is specific for Websphere.