我正在使用Spring Boot,RabbitMQ和WebSocket作为POC构建网络聊天,但我有最后一个要点:WebSockets
我希望我的ws客户端连接到特定的端点,例如/room/{id}当有新消息到达时,我希望服务器将响应发送给客户端,但是我搜索了类似内容但未找到。
目前,当消息到达时,我使用RabbitMQ对其进行处理,例如
container.setMessageListener(new MessageListenerAdapter(){
@Override
public void onMessage(org.springframework.amqp.core.Message message, Channel channel) throws Exception {
log.info(message);
log.info("Got: "+ new String(message.getBody()));
}
});
Run Code Online (Sandbox Code Playgroud)
我想要的是,而不是登录它,我想将其发送给客户端,例如: websocketManager.sendMessage(new String(message.getBody()))
我有客户端在 websocket 上像这样连接
var socket = new SockJS(this.props.stomp);
var stompClient = Stomp.over(socket);
var channel = "/room."+this.props.room.uid
var app = this;
stompClient.connect({room: this.props.room.uid}, function(frame) {
....
Run Code Online (Sandbox Code Playgroud)
在我的 Java 后端,我试图按照教程获取此标头:
public void onApplicationEvent(SessionConnectEvent event) {
StompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage());
String room = sha.getNativeHeader("room").get(0);
logger.debug("Connect event [sessionId: " + sha.getSessionId() +"; room: "+ room + " ]");
}
Run Code Online (Sandbox Code Playgroud)
但此时room为空。
我调试并发现了一个非常复杂的层次结构:aMessageHeaderAccessor包含一个映射,该映射包含一个 LinkedList,该映射具有一个nativeHeaders包含这些本机标头的键。
我的问题:有没有一种简单的方法来访问这个本机标头?到目前为止,我只得到像
MessageHeaderAccessor accessor = NativeMessageHeaderAccessor.getAccessor(event.getMessage(), SimpMessageHeaderAccessor.class);
accessor.getMessageHeaders();
Object header = accessor.getHeader("simpConnectMessage");
GenericMessage<?> generic = (GenericMessage<?>) accessor.getHeader("simpConnectMessage"); …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它读取文件的内容并为其编制索引.我将它们存储在磁盘本身,但现在我正在使用Amazon S3,因此以下方法不再起作用.
它是这样的:
def perform(docId)
@document = Document.find(docId)
if @document.file?
#You should't create a new version
@document.versionless do |doc|
@document.file_content = Cloudoc::Extractor.new.extract(@document.file.file)
@document.save
end
end
end
Run Code Online (Sandbox Code Playgroud)
@document.file返回FileUploader,并doc.file.file返回CarrierWave::Storage::Fog::File该类.
我如何获得真实文件?
我有两个这样的数组:
["1","7","8","10"]
Run Code Online (Sandbox Code Playgroud)
和
["1","2","3","6","9","11"]
Run Code Online (Sandbox Code Playgroud)
Place这些数组代表用户选择的一个类的 id 。我想选择得票最多的地点 id。我尝试过transpose,但由于数组大小不同,因此无法转置。
此示例的预期输出是:
{ "1" => 2, "7" => 1, "8" => 1, "10" => 1, "2" => 1, "3" => 1, "6" => 1, "9" => 1, "11" => 1 }
Run Code Online (Sandbox Code Playgroud) 我的Spring Boot应用程序中有以下配置:
@Configuration
@EnableAsync
@Slf4j
public class AsyncConfig {
private static final int BUFFER = 1024;
@Bean
public AsyncTaskExecutor singleThreadAsyncTaskExecutor(Environment env) {
RingBufferAsyncTaskExecutor rbAsyncExecutor = new RingBufferAsyncTaskExecutor(env);
rbAsyncExecutor.setName("rb-executor");
rbAsyncExecutor.setBacklog(BUFFER);
rbAsyncExecutor.setProducerType(ProducerType.SINGLE);
rbAsyncExecutor.setWaitStrategy(new YieldingWaitStrategy());
log.info("Async task executor loaded");
return rbAsyncExecutor;
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,cpu使用率达到100%(有时100个):
用visualvm调查,我看到了这一点
但是,当我删除AsyncTaskExecutorCPU使用率的实例化为0.4%时,visualvm显示我仅占CPU使用率的1%.
我在使用docker部署它时发现了这个问题,我看到我的主机使用率达到了上限.
我尝试将缓冲区大小(它是2048)降低到1024但没有任何改变.
没有这个bean,我的@Async服务不会异步工作.(No TaskExecutor bean found for async processing)
我通过Instagram验证,并获得了带范围的访问令牌follower_list.然后我试着找到我的粉丝列表:
https://api.instagram.com/v1/users/self/followed-by?access_token=123.456
我得到的只是一个空数组,如下所示
{
"pagination": {},
"meta": {
"code": 200
},
"data": []
}
Run Code Online (Sandbox Code Playgroud)
我真的不知道这是不是来自Instagram方面的问题,或者这是一个预期的行为,因为我在Sandbox模式(虽然文档说我甚至可以在Sandbox模式下获得真实数据)
我有一个 Spring Boot 应用程序,我要更新到 1.5.1。效果很好,直到我将 Sleuth 和 Zipkin 添加到类路径
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当这些行出现时,我得到
2017-02-22 22:33:05.331 ERROR [chathub-api,,,] 7581 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
Run Code Online (Sandbox Code Playgroud)
这是我的部门。管理
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
我试着改成达尔斯顿
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
但错误变得更加奇怪
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method …Run Code Online (Sandbox Code Playgroud) 我有一段代码,我将 a 导入BankAccountTransaction到 aBankAccount
bank_account.with_lock do
transactions.each do |transaction|
import(bank_account, transaction)
end
end
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我需要为其编写一个 RSpec 案例,这样我就可以 100% 确定我不会两次导入事务。
我写了以下助手
module ConcurrencyHelper
def make_concurrent_calls(function, concurrent_calls: 2)
threads = Array.new(concurrent_calls) do
thread = Thread.new { function.call }
thread.abort_on_exception = true
thread
end
threads.each(&:join)
end
end
Run Code Online (Sandbox Code Playgroud)
我在 RSpec 上调用它
context 'when importing the same transaction twice' do
subject(:concurrent_calls) { make_concurrent_calls(operation) }
let!(:operation) { -> { described_class.call(params) } }
let(:filename) { 'single-transaction-response.xml' }
it 'creates only one transaction' do
expect { …Run Code Online (Sandbox Code Playgroud) 我在这样的反应组件中有一个函数
addItem: function(data) {
console.log(data)
var oldMessages = this.state.messages;
oldMessages.push({id: data.uid, content: data});
this.setState({messages: oldMessages});
this.scrollAndSetTimestamps()
this.updateCount()
},
componentDidMount: function() {
this.loadLatestMessages();
var socket = new SockJS('http://127.0.0.1:8080/stomp');
var stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
// subscribe to the /room.uid endpoint
stompClient.subscribe("/room.1247016", function(data) {
var message = data.body;
console.log("Received: "+message);
this.addItem();
});
});
},
Run Code Online (Sandbox Code Playgroud)
事实证明,addItem当消息到达时找不到.如何在anon函数中调用react方法?
我使用以下配置在DC/OS上部署了服务
当我访问此地址(http://eureka.marathon.l4lb.thisdcos.directory:8761/)时,它表示无法访问该站点,尽管我的仪表板上的所有服务都是健康的.
如何访问服务的公共IP?
我不知道它是否相关,但当我查看我的公共奴隶的负载均衡配置时,我得到了 0 of 2 instances in service
spring-boot ×4
java ×3
ruby ×3
spring ×2
amazon-s3 ×1
carrierwave ×1
dcos ×1
instagram ×1
javascript ×1
mapreduce ×1
marathon ×1
rabbitmq ×1
reactjs ×1
reactor ×1
sockjs ×1
spring-cloud ×1
stomp ×1
visualvm ×1
zipkin ×1