-
Notifications
You must be signed in to change notification settings - Fork 23
test header capture #895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
test header capture #895
Changes from 8 commits
1b482ae
7c934a7
883fba7
e47121a
916f656
1c5adb3
30c461d
ba459e2
c6c4df1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,22 +70,20 @@ public static boolean isDebugInCI() { | |
|
|
||
| private static boolean probeListeningDebugger(int port) { | ||
| // the most straightforward way to probe for an active debugger listening on port is to start | ||
| // another JVM | ||
| // with the debug options and check the process exit status. Trying to probe for open network | ||
| // port messes with | ||
| // the debugger and makes IDEA stop it. The only downside of this is that the debugger will | ||
| // first attach to this | ||
| // probe JVM, then the one running in a docker container we are aiming to debug. | ||
| // another JVM with the debug options and check the process exit status. Trying to probe for | ||
| // open network port messes with the debugger and makes IDEA stop it. The only downside of this | ||
| // is that the debugger will first attach to this probe JVM, then the one running in a docker | ||
| // container we are aiming to debug. | ||
| try { | ||
| Process process = | ||
| new ProcessBuilder() | ||
| .command( | ||
| JavaExecutable.getBinaryPath().toString(), | ||
| JavaExecutable.getBinaryPath(), | ||
| jvmDebugArgument("localhost", port), | ||
| "-version") | ||
| .start(); | ||
| process.waitFor(5, TimeUnit.SECONDS); | ||
| return process.exitValue() == 0; | ||
| boolean processExit = process.waitFor(5, TimeUnit.SECONDS); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] fixing minor bug when trying to debug the remote app running in docker. |
||
| return processExit && process.exitValue() == 0; | ||
| } catch (InterruptedException | IOException e) { | ||
| return false; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package co.elastic.otel.test; | ||
|
|
||
| import javax.jms.JMSException; | ||
| import javax.jms.Message; | ||
| import javax.jms.TextMessage; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.jms.core.JmsTemplate; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import java.util.Enumeration; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/messages") | ||
| public class MessagingController { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] adding an HTTP controller to receive/send messages with JMS API. |
||
|
|
||
| private static final String DESTINATION = "messages-destination"; | ||
|
|
||
| @Autowired | ||
| public MessagingController(JmsTemplate jmsTemplate) { | ||
| this.jmsTemplate = jmsTemplate; | ||
| } | ||
|
|
||
| private final JmsTemplate jmsTemplate; | ||
|
|
||
| @RequestMapping("/send") | ||
| public String send( | ||
| @RequestParam(name = "headerName", required = false) String headerName, | ||
| @RequestParam(name= "headerValue", required = false) String headerValue) { | ||
| jmsTemplate.send(DESTINATION, session -> { | ||
| TextMessage message = session.createTextMessage("Hello World"); | ||
| if (headerName != null && headerValue != null) { | ||
| message.setStringProperty(headerName, headerValue); | ||
| } | ||
| return message; | ||
| }); | ||
| return null; | ||
| } | ||
|
|
||
| @RequestMapping("/receive") | ||
| public String receive() throws JMSException { | ||
| Message received = jmsTemplate.receive(DESTINATION); | ||
| if (received instanceof TextMessage) { | ||
| TextMessage textMessage = (TextMessage) received; | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("message: [") | ||
| .append(textMessage.getText()) | ||
| .append("]"); | ||
|
|
||
| Enumeration<?> propertyNames = textMessage.getPropertyNames(); | ||
| if(propertyNames.hasMoreElements()) { | ||
| sb.append(", headers: ["); | ||
| int count = 0; | ||
| while (propertyNames.hasMoreElements()) { | ||
| String propertyName = (String) propertyNames.nextElement(); | ||
| sb.append(count++ > 0 ? ", " : "") | ||
| .append(propertyName) | ||
| .append(" = ") | ||
| .append(textMessage.getStringProperty(propertyName)); | ||
| } | ||
| sb.append("]"); | ||
|
|
||
| } | ||
|
|
||
| return sb.toString(); | ||
| } else { | ||
| return "nothing received"; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # use an in-process activemq artemis instance | ||
| spring.artemis.mode=embedded | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [for reviewer] provides an in-process ActiveMQ Artemis instance, the implementation is provided by the |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[for reviewer] no longer used, thus we can remove it.