我试图用jQuery调用我的Java RESTFUL API有点困难.
调试我发现调用了OPTIONS和GET方法但是当GET方法在服务器中完成时,不会检索json并且在broswer中引发错误.
选项请求
OPTIONS /PTGServices/ptgapi/v1/clients/1/ngos HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Cache-Control: max-age=0
Access-Control-Request-Method: GET
Origin: http://localhost:8181
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36
Access-Control-Request-Headers: accept, cache-control, x-custom-1, x-custom-2, authorization
Accept: */*
Referer: http://localhost:8181/jquerysample/local/index.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-ES,es;q=0.8,en;q=0.6
Run Code Online (Sandbox Code Playgroud)
选项响应
HTTP/1.1 204 Sin Contenido
Server: Apache-Coyote/1.1
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:8181
Access-Control-Allow-Methods: GET, POST, PUT
Access-Control-Allow-Headers: Authorization,Cache-control,Content-Type,Origin,X-requested-with,X-custom-1,X-custom-2,WithCredentials
Access-Control-Max-Age: 60
Date: Mon, 20 Jan 2014 14:49:25 GMT
Run Code Online (Sandbox Code Playgroud)
获得请求
Accept:*/*
Authorization:Basic dXNlcjp1c2Vy
Cache-Control:no-cache
Origin:http://localhost:8181
Referer:http://localhost:8181/jquerysample/local/index.html
User-Agent:Mozilla/5.0 (Windows NT …Run Code Online (Sandbox Code Playgroud) 我得到了一个例外Dispatcher has no subscribers,outboundChannel无法弄清楚原因.我确信它很简单,我已将我的代码删除到下面的一个非常简单的示例:
我的背景是:
<bean id="requestService"
class="com.sandpit.RequestService" />
<integration:channel id="inboundChannel" />
<integration:service-activator id="service"
input-channel="inboundChannel"
output-channel="outboundChannel"
ref="requestService"
method="handleRequest" />
<integration:channel id="outboundChannel" />
<integration:gateway id="gateway"
service-interface="com.sandpit.Gateway"
default-request-channel="inboundChannel"
default-reply-channel="outboundChannel" />
<bean class="com.sandpit.GatewayTester">
<property name="gateway"
ref="gateway" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我的Java代码是:
public interface Gateway {
String receive();
void send(String message);
}
public class RequestService {
public String handleRequest(String request) {
return "Request received: " + request;
}
}
public class GatewayTester implements ApplicationListener<ContextRefreshedEvent> {
private Gateway gateway;
public void setGateway(Gateway gateway) …Run Code Online (Sandbox Code Playgroud) 我正在试验Spring Reactor 3组件和Spring Integration来从JMS队列创建一个反应流(Flux).
我试图从JMS队列(使用Spring Integration的ActiveMQ)创建一个反应流(Spring Reactor 3 Flux),以便客户端异步获取JMS消息.我相信我已正确连接所有内容但客户端在服务器停止之前不会收到任何JMS消息.然后将所有消息"推送"到客户端一次.
任何帮助,将不胜感激.
这是我用来配置JMS,Integration组件和被动发布者的配置文件:
@Configuration
@EnableJms
@EnableIntegration
public class JmsConfiguration {
@Value("${spring.activemq.broker-url:tcp://localhost:61616}")
private String defaultBrokerUrl;
@Value("${queues.patient:patient}")
private String patientQueue;
@Autowired
MessageListenerAdapter messageListenerAdapter;
@Bean
public DefaultJmsListenerContainerFactory myFactory(
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory =
new DefaultJmsListenerContainerFactory();
configurer.configure(factory, jmsConnectionFactory());
return factory;
}
@Bean
public Queue patientQueue() {
return new ActiveMQQueue(patientQueue);
}
@Bean
public ActiveMQConnectionFactory jmsConnectionFactory() {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL(defaultBrokerUrl);
connectionFactory.setTrustedPackages(Arrays.asList("com.sapinero"));
return connectionFactory;
}
// Set the jackson message converter
@Bean
public JmsTemplate jmsTemplate() …Run Code Online (Sandbox Code Playgroud) java spring spring-integration reactive-programming project-reactor
我想使用Spring Integration来实现基于内容的路由器,如果表达式值与任何映射都不匹配,则使用默认输出通道.这是我的bean定义:
<int:router input-channel="channel_in" default-output-channel="channel_default" expression="payload.name">
<int:mapping value="foo" channel="channel_one" />
<int:mapping value="bar" channel="channel_two" />
Run Code Online (Sandbox Code Playgroud)
但是,似乎从不使用默认输出通道.如果表达式评估为例如'baz',则路由器似乎正在寻找名为'baz'的频道,而不是路由到'channel_default'频道:
org.springframework.integration.MessagingException: failed to resolve channel name 'baz'
Caused by: org.springframework.integration.support.channel.ChannelResolutionException:
failed to look up MessageChannel bean with name 'baz'
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'baz' is defined
Run Code Online (Sandbox Code Playgroud)
我想要的是使用XML命名空间,或者我是否需要编写自己的实现?
我是微服务的新手,我正在尝试将我的项目转变为基于微服务的项目.我的问题是弄清楚每个服务如何相互通信.
首先,我探讨了REST样式服务,但如果每个服务都基于HTTP REST,那么它们之间如何相互"交谈"呢?
然后我尝试学习Spring Integration,但后来变得更加清晰,他们应该如何沟通,因为现在我想到我可能需要使用RabbitMQ作为前端和微服务后端之间的中间件.
我也遇到了云和Docker技术,所以我猜每个服务都应该在云端,但它仍然没有说明服务如何通信.
我正在使用Java,Spring技术.
如果有人能让我更好地了解事情应该如何,我会很高兴.
我是春天的初学者,我必须为学校做一个项目.我可以使用Spring Batch和Integration进行哪种项目.我知道我可以将文件写入目录,编写,读取和修改逗号分隔文件,但我无法描绘可以将这些技术结合起来的场景.
反正手动启动/初始化通道适配器了吗?
我在context.xml中有两对入站/出站适配器,并希望在运行时决定我想要启动哪一个.
编辑:
具体方案:
我有一个客户端,可以在运行时配置为mqtt发布者或订阅者.
我的context.xml看起来像这样:
<int-mqtt:message-driven-channel-adapter
client-id="foo"
auto-startup="true"
url="tcp://192.168.97.164:1883"
topics="testtopic/#"
channel="writeToFile" />
<file:outbound-channel-adapter
id="writeToFile"
auto-startup="true"
directory="./test/out"
delete-source-files="false"/>
<int:transformer id="Transformer"
ref="MessageTransformer"
input-channel="readFromFile"
output-channel="mqttOut"
method="bytesFromFile" />
<bean id="MessageTransformer" class="MessageTransformer"/>
<int-mqtt:outbound-channel-adapter
id="mqttOut"
client-id="foo"
url="tcp://192.168.97.164:1883"
auto-startup="false"
default-qos="1"
default-retained="true"
default-topic="testtopic/bla"
/>
<file:inbound-channel-adapter
auto-startup="false"
id="readFromFile"
directory="./test/in"
filename-pattern="myFile*">
<int:poller id="poller"
fixed-rate="5000" />
</file:inbound-channel-adapter>
Run Code Online (Sandbox Code Playgroud)
如您所见,我有两个设置:
1.订阅者案例:读取mqtt消息 - >写入文件
2.发布者案例:从目录中轮询文件 - >通过mqtt发送
我在运行时决定应用什么设置.
那么请你告诉我这个控制总线的东西究竟适合这里吗?
我用Spring Boot创建了一个Spring Integration应用程序.我想知道如何使用Spring Boot配置JMX.我相信在使用Spring Boot Actuator时默认配置JMX.
我是否需要配置其他任何能够为Spring Integration导出MBean的东西?
我看到的大多数示例在applicationContext.xml中都有以下行
<context:mbean-export/>
<context:mbean-server/>
Run Code Online (Sandbox Code Playgroud)
我的Application.java类看起来像这样.
package com.jbhunt.app.consumerappointmentintegration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ComponentScan
@EnableAutoConfiguration
@ImportResource("classpath:META-INF/spring/integration/spring-integration-context.xml")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
将此行添加到配置似乎不会导出Spring Integration mbeans
@EnableIntegrationMBeanExport(server = "mbeanServer", defaultDomain="my.company.domain")
Run Code Online (Sandbox Code Playgroud)
在Intellij中,我们有一个功能来生成各种弹簧集成通道中的消息/事件处理流程图吗?鉴于复杂的Spring集成XML配置文件包含各种变换器,入站,出站通道和服务激活器,有没有办法以图形方式查看所有这些通道的流量?
有这样的图生成工具吗?
注意:它不仅仅是spring beans图,而是使用spring集成的实际消息流
我有一个Spring集成流程,涉及异步执行,从网关返回值到控制器,返回值后继续集成流程.
这是网关:
@MessagingGateway
public interface GW {
@Gateway(requestChannel = "f.input")
Task input(Collection<MessengerIncomingRequest> messages);
}
Run Code Online (Sandbox Code Playgroud)
这是流程:
@Bean
IntegrationFlow jFlow() {
return IntegrationFlows.from(
MessageChannels.executor("f.input", executor()))
.split()
.channel(MessageChannels.executor(executor()))
.transform(transformer)
.channel(routerChannel())
.get();
}
@Bean
ThreadPoolTaskExecutor executor() {
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
...
return pool;
}
@Bean
MessageChannel routerChannel() {
return MessageChannels
.publishSubscribe("routerChannel", executor())
.get();
}
@Bean
IntegrationFlow routerChannelFlow() {
return IntegrationFlows
.from(routerChannel())
.publishSubscribeChannel(s -> s
.subscribe(f -> f.bridge(null))
.subscribe(process()))
.get();
}
@Bean
IntegrationFlow process() {
return f ->
f.route(p -> p.getKind().name(),
m -> …Run Code Online (Sandbox Code Playgroud) java ×6
spring ×6
ajax ×1
cors ×1
javascript ×1
jmx ×1
jquery ×1
rest ×1
routing ×1
spring-batch ×1
spring-boot ×1