@Override protected final Object splitMessage(Message<?> message) { return this.messageProcessor.processMessage(message); }
@Override protected Object handleRequestMessage(Message<?> message) { return this.processor.processMessage(message); }
@Override protected Object doReceive() { return this.messageProcessor.processMessage(null); }
public Object processMessage(Message<?> message) { return this.targetProcessor.processMessage(message); }
@Override protected List<Object> getChannelKeys(Message<?> message) { Object result = this.messageProcessor.processMessage(message); return Collections.singletonList(result); }
public final boolean accept(Message<?> message) { Object result = this.messageProcessor.processMessage(message); Assert.notNull(result, "result must not be null"); Assert.isAssignable(Boolean.class, result.getClass(), "a boolean result is required"); return (Boolean) result; }
@Override public boolean accept(Message<?> message) { String key = this.keyStrategy.processMessage(message); Long timestamp = message.getHeaders().getTimestamp(); String value = (this.valueStrategy != null) ? this.valueStrategy.processMessage(message) : (timestamp == null ? "0" : Long.toString(timestamp)); return this.metadataStore.putIfAbsent(key, value) == null; }
@Override public T processMessage(Message<?> message) { if (this.delegate == null) { Object target = this.beanFactory.getBean(this.beanName); MethodInvokingMessageProcessor<T> methodInvokingMessageProcessor = new MethodInvokingMessageProcessor<>(target, this.methodName); methodInvokingMessageProcessor.setBeanFactory(this.beanFactory); this.delegate = methodInvokingMessageProcessor; } return this.delegate.processMessage(message); }
private void addHeadersFromMessageProcessor(Message<?> message, AbstractIntegrationMessageBuilder<?> messageBuilder) { if (this.messageProcessor != null) { Object result = this.messageProcessor.processMessage(message); if (result instanceof Map) { MessageHeaders messageHeaders = message.getHeaders(); Map<?, ?> resultMap = (Map<?, ?>) result; for (Entry<?, ?> entry : resultMap.entrySet()) { Object key = entry.getKey(); if (key instanceof String) { if (this.defaultOverwrite || messageHeaders.get(key) == null) { messageBuilder.setHeader((String) key, entry.getValue()); } } else if (logger.isDebugEnabled()) { logger.debug("ignoring value for non-String key: " + key); } } } else if (logger.isDebugEnabled()) { logger.debug("expected a Map result from processor, but received: " + result); } } }
@Override public MqttMessage fromMessage(Message<?> message, Class<?> targetClass) { byte[] payloadBytes = messageToMqttBytes(message); MqttMessage mqttMessage = new MqttMessage(payloadBytes); Integer qos = this.qosProcessor.processMessage(message); mqttMessage.setQos(qos == null ? this.defaultQos : qos); Boolean retained = this.retainedProcessor.processMessage(message); mqttMessage.setRetained(retained == null ? this.defaultRetained : retained); return mqttMessage; }
@Override protected void handleMessageInternal(Message<?> message) throws Exception { Object mqttMessage = this.converter.fromMessage(message, Object.class); String topic = this.topicProcessor.processMessage(message); if (topic == null && this.defaultTopic == null) { throw new MessageHandlingException(message, "No topic could be determined from the message and no default topic defined"); } publish(topic == null ? this.defaultTopic : topic, mqttMessage, message); }
@Override public final Message<?> transform(Message<?> message) { Object result = this.messageProcessor.processMessage(message); if (result == null) { return null; } if (result instanceof Message<?>) { return (Message<?>) result; } MessageHeaders requestHeaders = message.getHeaders(); return getMessageBuilderFactory() .withPayload(result) .filterAndCopyHeadersIfAbsent(requestHeaders, this.selectiveHeaderPropagation ? this.notPropagatedHeaders : null) .build(); }
@Test public void testInt3166GroovyScriptExecutingMessageProcessorPerformance() throws Exception { final Message<?> message = new GenericMessage<Object>("test"); final AtomicInteger var1 = new AtomicInteger(); final AtomicInteger var2 = new AtomicInteger(); String script = "var1.incrementAndGet(); Thread.sleep(100); var2.set(Math.max(var1.get(), var2.get())); var1.decrementAndGet()"; ScriptSource scriptSource = new StaticScriptSource(script, Script.class.getName()); final MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource, message1 -> { Map<String, Object> variables = new HashMap<String, Object>(2); variables.put("var1", var1); variables.put("var2", var2); return variables; }); ExecutorService executor = Executors.newFixedThreadPool(10); for (int i = 0; i < 10; i++) { executor.execute(() -> processor.processMessage(message)); } executor.shutdown(); assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS)); assertTrue(var2.get() > 1); }
Message<?> message = new GenericMessage<String>("Hello, world!"); assertEquals("foobar", TestUtils.getPropertyValue(endpoint, "routingKeyGenerator", MessageProcessor.class) .processMessage(message)); assertEquals("barbar", TestUtils.getPropertyValue(endpoint, "exchangeNameGenerator", MessageProcessor.class) .processMessage(message)); assertEquals("bazbar", TestUtils.getPropertyValue(endpoint, "correlationDataGenerator", MessageProcessor.class) .processMessage(message));
@Test public void testSimpleExecutionWithContext() { Message<?> message = MessageBuilder.withPayload("\"spam is $spam foo is $headers.foo\"") .setHeader("foo", "bar").build(); ScriptVariableGenerator scriptVariableGenerator = new DefaultScriptVariableGenerator(Collections.singletonMap("spam", "bucket")); MessageProcessor<Object> processor = new GroovyCommandMessageProcessor(scriptVariableGenerator); Object result = processor.processMessage(message); assertEquals("spam is bucket foo is bar", result.toString()); }
@Test public void testRefreshableScriptExecutionWithAlwaysRefresh() throws Exception { String script = "return \"payload is $payload, header is $headers.testHeader\""; Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build(); TestResource resource = new TestResource(script, "simpleTest"); ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, 0); MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource); // process with the first script Object result = processor.processMessage(message); assertEquals("payload is foo, header is bar", result.toString()); // change script, but since refresh-delay is less then 0 we should still se old script executing resource.setScript("return \"payload is $payload\""); // process and see assert that the old script is used result = processor.processMessage(message); assertEquals("payload is foo", result.toString()); resource.setScript("return \"payload is 'hello'\""); // process and see assert that the old script is used result = processor.processMessage(message); assertEquals("payload is 'hello'", result.toString()); }
@Test @Ignore("Very sensitive to the time") public void testRefreshableScriptExecution() throws Exception { String script = "return \"payload is $payload, header is $headers.testHeader\""; Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build(); TestResource resource = new TestResource(script, "simpleTest"); ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, 2000L); MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource); // should be the original script Object result = processor.processMessage(message); assertEquals("payload is foo, header is bar", result.toString()); //reset the script with the new string resource.setScript("return \"payload is $payload\""); Thread.sleep(20L); // should still assert to the old script because not enough time elapsed for refresh to kick in result = processor.processMessage(message); assertEquals("payload is foo, header is bar", result.toString()); // sleep some more, past refresh time Thread.sleep(2000L); // now you go the new script resource.setScript("return \"payload is $payload\""); result = processor.processMessage(message); assertEquals("payload is foo", result.toString()); }
@Override protected Object doReceive() { return this.messageProcessor.processMessage(null); } }
@Test public void testRefreshableScriptExecutionWithInfiniteDelay() throws Exception { String script = "return \"payload is $payload, header is $headers.testHeader\""; Message<?> message = MessageBuilder.withPayload("foo").setHeader("testHeader", "bar").build(); TestResource resource = new TestResource(script, "simpleTest"); ScriptSource scriptSource = new RefreshableResourceScriptSource(resource, -1L); MessageProcessor<Object> processor = new GroovyScriptExecutingMessageProcessor(scriptSource); // process with the first script Object result = processor.processMessage(message); assertEquals("payload is foo, header is bar", result.toString()); // change script, but since refresh-delay is less then 0 we should still se old script executing resource.setScript("return \"payload is $payload\""); // process and see assert that the old script is used result = processor.processMessage(message); assertEquals("payload is foo, header is bar", result.toString()); }
@Override protected Object doReceive() { return this.messageProcessor.processMessage(null); } }