I am beginner to Quarkus lambda and when I am looking for how to debug the Quarkus lambda then everyone is showing with REST API endpoints, is there any way to debug the Quarkus app using lambda handler ?
I know how to start the app in dev mode but I am struggling with invoking the handler method.
You can use SAM CLI for local debugging and testing. Here is the official documentation from quarkus.
It's really important that you follow the sequence.
Step-1:
sam local start-api --template target/sam.jvm.yaml -d 5005
Step-2:
Hit your API using your favourite rest client
Step-3
Add a Remote JVM debug configuration in your IDE, set your breakpoints and start debugging.
You can actually just add a Main class and set up a usual Run Configuration.
import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.Quarkus;
#QuarkusMain
public class Main {
public static void main(String ... args) {
System.out.println("Running main method");
Quarkus.run(args);
}
}
After that, just use curl or Postman to invoke the endpoint.
By default, the lambda handler starts on port 8080.
You can override it by passing
-Dquarkus.lambda.mock-event-server.dev-port=9999
So the curl will look like:
curl -XGET "localhost:9999/hello"
if the definition of the resource class looks like:
#Path("/hello")
public class GreetingResource {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello jaxrs";
}
}
Add a breakpoint in the Resource class and start the Main class in Debug mode. This will actually pause during a debug on a breakpoint.
You can just run mvn quarkus:dev and connect a remote debugger to it on port 5005 as shown in this image
Once quarkus is started in dev mode and you connect the remote debugger you can use Postman to send a request. Your breakpoints will be evaluated.
Related
I basically followed the steps described here: https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#configure-spring-boot-project
My application.properties contains the following:
spring.neo4j.uri=neo4j://localhost:7687
spring.neo4j.authentication.username=neo4j
spring.neo4j.authentication.password=verySecret357
I have a Neo4jConfiguration Bean which only specifies the TransactionManager, rest is (supposedly) taken care of by spring-boot-starter-data-neo4j:
#Configuration
public class Neo4jConfiguration {
#Bean
public ReactiveNeo4jTransactionManager reactiveTransactionManager(Driver driver,
ReactiveDatabaseSelectionProvider databaseNameProvider) {
return new ReactiveNeo4jTransactionManager(driver, databaseNameProvider);
}
}
Neo4j (5.3.0) runs in a Docker container I started with
docker run -d --name neo4j -p 7474:7474 -p 7687:7687 -e 'NEO4J_AUTH=neo4j/verySecret357' neo4j:4.4.11-community
I can access it through HTTP on my localhost:7474 and can authenticate using the credentials above.
Now, when I run my springboot app and try to create Nodes in Neo4j, I keep getting the same exception:
org.neo4j.driver.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
Running in debug, it however seems the client authentication scheme is correctly set:
Any thoughts on what I might be doing wrong ?
Edit: one thing though, I would assume that the "authToken" would contain a base64-encoded String (username:password) as the scheme is basic auth. It looks like it's not the case (using neo4j-java-driver:5.2.0).
Edit: seems to be related to the Docker image. A standalone neo4j instance works fine.
I'm new in Spring and I have a problem when I run Spring WEB in VM.
Test on local computer works:
I run app mvn spring-boot:run -Dspring-boot.run.profiles=test and check request:
curl -X POST ``http://localhost:8080/api/v1/dictionary/yandex-alice-skill`` -H "Content-Type: application/json" -d "{}"
and get {"response":{"text":"Hi! I can help you to learn words.","end_session":false},"version":"1.0"}
When I run app in VM and try to get json in my VM everything works fine too:
BUT when I try to get json in my local computer I get 404
Page have 404, but why I can't get json? How to properly connect to my virtual machine?
Controller:
#RestController
#Slf4j
#RequestMapping("/api/v1/dictionary/yandex-alice-skill")
#RequiredArgsConstructor
public class DictionaryController {
#Autowired
private DictionaryService dictionaryService;
#PostMapping
public #ResponseBody talkYandexAlice(
#RequestBody YandexAliceRequest request) {
return dictionaryService.talkYandexAlice(request);
}
}
I want to get json, but I get HTML from server.
It is possible to configure Consul callback "POST" to a rest API every time that a service status is updated?
I've found "Watch" feature in documentation (https://www.consul.io/docs/dynamic-app-config/watches#http-endpoint), but seems like this feature is not to automatically Consul call some API when a services event is called.
Please, if someone know how to do this task, will be very thankful!
I’ve found a solution:
In agent command (to start Consul):
sudo consul agent --dev --client 0.0.0.0 --config-file ./path/consul-agent.json
In consul-agent.json file:
{
“watches”: [
{
“type”: “services”,
“handler_type”: “http”,
“http_handler_config”: {
“path”: “https://localhost/routetocall”,
“method”: “POST”,
“header”: { “Authentication”: [“something”] },
“timeout”: “10s”,
“tls_skip_verify”: true
}
}
]
}
I am running spring boot application on windows and its using windows-1252 encoding. However stand alone java program is using UTF-8 encodeing. How do I force spring boot to use UTF-8. below code outputs ????. I use the below command using jar -jar target\spring-boot-example.jar
I verified that in power shell program that default character set is windows-1252 (System.Text.Encoding)::Default
public class SpringBootConsoleApplication implements CommandLineRunner {
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootConsoleApplication.class, args);
}
#Override
public void run(String... args) throws Exception {
System.out.println("Default Charset=" + Charset.defaultCharset());
System.out.println("test::" +"الرياض");
}
}
I tried the below options in application.properties without success:
# Charset of HTTP requests and responses. Added to the "Content-Type" header if not set explicitly.
spring.http.encoding.charset=UTF-8
# Enable http encoding support.
spring.http.encoding.enabled=true
# Force the encoding to the configured charset on HTTP requests and responses.
spring.http.encoding.force=true
Try running your app with -Dfile.encoding=UTF8 in the command line.
Example:
java -jar -Dfile.encoding=UTF8 target/myapp-0.0.1-SNAPSHOT.jar
The problem seems to be your stdout, not the code. I suggest you create a simple main class, without Spring Boot, or any external dependencies, and print UTF-8 characters. I'm on a Mac, and the following code prints find for me:
public class Main {
public static void main(String[] args) {
System.out.println("Default Charset=" + Charset.defaultCharset());
System.out.println("test::" + "الرياض");
}
}
Default Charset=UTF-8
test::الرياض
Another thing you may want to try is writing it to a file instead of stdout.
Edit:
I think you're barking the wrong tree. No one uses Spring Boot for printing to stdout. The spring.http.encoding properties you'd set are actually HttpEncodingProperties which Boot uses to auto configure encoding using HttpEncodingAutoConfiguration. But all that's for a HTTP request, not for printing to stdout. Any application that deserves to go to Prod should use a logger, and not System.out.println.
#AbjitSarkar #JC Carrillo this issue seems to be with windows environment. I deployed the same code on UbuntuVM and everything seems to be fine.
Thank you for listening to me and giving me tips to explore !!
i'm trying to pass command line arguments in my Spring Boot Yarn application and am having difficulties. i understand that i can set these in the yml document spring.yarn.appmaster.launchcontext.arguments but how can it from the command line? like java -jar MyYarnApp.jar {arg0} {arg1} and get access to it from my #YarnContainer?
i've discovered that #YarnProperties maps to spring.yarn.appmaster.launchcontext.arguments but i want to set them from the command line, not in the yml
You are pretty close on this when you found spring.yarn.client.launchcontext.arguments and spring.yarn.appmaster.launchcontext.arguments. We don't have settings which would automatically pass all command-line arguments from a client into an appmaster which would then pass them into a container launch context. Not sure if we even want to do that because you surely want to be on control what happens with YARN container launch context. User using a client could then potentially pass a rogue arguments along a food chain.
Having said that, lets see what we can do with our Simple Single Project YARN Application Guide.
We still need to use those launch context arguments to define our command line parameters to basically map how things are passed from a client into an appmaster into a container.
What I added in application.yml:
spring:
yarn:
client:
launchcontext:
arguments:
--my.appmaster.arg1: ${my.client.arg1:notset1}
appmaster:
launchcontext:
arguments:
--my.container.arg1: ${my.appmaster.arg1:notset2}
Modified HelloPojo in Application class:
#YarnComponent
#Profile("container")
public static class HelloPojo {
private static final Log log = LogFactory.getLog(HelloPojo.class);
#Autowired
private Configuration configuration;
#Value("${my.container.arg1}")
private String arg1;
#OnContainerStart
public void onStart() throws Exception {
log.info("Hello from HelloPojo");
log.info("Container arg1 value is " + arg1);
log.info("About to list from hdfs root content");
FsShell shell = new FsShell(configuration);
for (FileStatus s : shell.ls(false, "/")) {
log.info(s);
}
shell.close();
}
}
Notice how I added arg1 and used #Value to map it with my.container.arg1. We can either use #ConfigurationProperties or #Value which are normal Spring and Spring Boot functionalities and there's more in Boot's reference docs how to use those.
You could then modify AppIT unit test:
ApplicationInfo info = submitApplicationAndWait(Application.class, new String[]{"--my.client.arg1=arg1value"});
and run build with tests
./gradlew clean build
or just build it without running test:
./gradlew clean build -x test
and then submit into a real hadoop cluster with your my.client.arg1.
java -jar build/libs/gs-yarn-basic-single-0.1.0.jar --my.client.arg1=arg1value
Either way you see arg1value logged in container logs:
[2014-07-18 08:49:09.802] boot - 2003 INFO [main] --- ContainerLauncherRunner: Running YarnContainer with parameters [--spring.profiles.active=container,--my.container.arg1=arg1value]
[2014-07-18 08:49:09.806] boot - 2003 INFO [main] --- Application$HelloPojo: Container arg1 value is arg1value
Using format ${my.client.arg1:notset1} also allows you to automatically define a default value notset1 if my.client.arg1 is omitted by user. We're working on Spring Application Context here orchestrated by Spring Boot so all the goodies from there are in your disposal
If you need more precise control of those user facing arguments(using args4j, jopt, etc) then you'd need to have a separate code/jar for client/appmaster/container order to create a custom client main method. All the other Spring YARN getting started guides are pretty much using multi-project builds so look at those. For example if you just want to have first and second argument value without having a need to use full --my.client.arg1=arg1value on a command line.
Let us know if this works for you and if you have any other ideas to make things simpler.