Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache kafka 卡夫卡的气氛不';不要发送广播信息_Apache Kafka_Apache Zookeeper_Broadcast_Atmosphere - Fatal编程技术网

Apache kafka 卡夫卡的气氛不';不要发送广播信息

Apache kafka 卡夫卡的气氛不';不要发送广播信息,apache-kafka,apache-zookeeper,broadcast,atmosphere,Apache Kafka,Apache Zookeeper,Broadcast,Atmosphere,我对大气有这种依赖 <dependency> <groupId>org.atmosphere</groupId> <artifactId>atmosphere-runtime</artifactId> <version>2.5.4</version> </dependency> 在此模式下到达对象“资源”已满 AtmosphereResource{ uu

我对大气有这种依赖

<dependency>
    <groupId>org.atmosphere</groupId>
    <artifactId>atmosphere-runtime</artifactId>
    <version>2.5.4</version>
</dependency>
在此模式下到达对象“资源”已满

AtmosphereResource{
           uuid=5348f619-df31-4bf6-a4eb-654ba64ef886,
           transport=WEBSOCKET,
           isInScope=true,
           isResumed=false,
           isCancelled=false,
           isSuspended=true,
           broadcasters=/clinicalevent/manager,
           isClosedByClient=false,
           isClosedByApplication=false,
           action=Action{timeout=-1, type=SUSPEND}}
对于卡夫卡库,“资源”对象是空的。到达空值不会广播到浏览器

这是我的大气资源课

package eu.dedalus.sop.o4c.servlets.atmosphere.clinicalevent;
import java.io.IOException;
import org.atmosphere.config.service.Disconnect;
import org.atmosphere.config.service.ManagedService;
import org.atmosphere.config.service.Message;
import org.atmosphere.config.service.Ready;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import com.owlike.genson.Genson;
import eu.dedalus.sop.log4j.LogManagerSOP;
import eu.dedalus.sop.log4j.LoggerSOP;
import eu.dedalus.sop.o4c.models.common.atmosphere.DataEntryOperation;

@ManagedService(path = "/clinicalevent/manager")
public final class ClinicalEventManager {

private static final LoggerSOP logger = LogManagerSOP.getLogger(ClinicalEventManager.class);
private static final Genson genson = new Genson();

@Ready
public final void onReady(final AtmosphereResource r) {
    logger.info("Browser " + r.uuid() + " connected.");
}

@Disconnect
public final void onDisconnect(final AtmosphereResourceEvent event) {
    if (event.isCancelled())
        logger.info("Browser " + event.getResource().uuid() + " unexpectedly disconnected");
    else if (event.isClosedByClient())
        logger.info("Browser " + event.getResource().uuid() + " closed the connection");
}

@Message(encoders = {
        ClinicalEventManagerEncoderDecoder.class
}, decoders = {
        ClinicalEventManagerEncoderDecoder.class
})
public final DataEntryOperation onMessage(final DataEntryOperation message) throws IOException {
    logger.info(message.getUser() + " just sent " + genson.serialize(message));
    return message;
}
}
我是卡夫卡

bootstrap.servers=localhost:9092
group.id=clinicaleventmanager
zk.connect=localhost:2181
zookeeper.connect=localhost:2181
这是web.xml中的AtmosphereServlet

<servlet>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <async-supported>true</async-supported>
    <init-param>
        <param-name>org.atmosphere.websocket.maxTextMessageSize</param-name>
        <param-value>1048576</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.kafka.propertiesFile</param-name>
        <param-value>WEB-INF/classes/kafka.properties</param-value>
    </init-param>  
    <load-on-startup>2</load-on-startup>
</servlet>

有什么问题吗?

问题出在kafkabroadcaster上。同学们!!!!In:@Override public void outgoingBroadcast(对象消息){logger.trace({}outgoingBroadcast{},主题,消息);//TODO:防止消息往返.producer.send(new ProducerRecord(主题,message.toString());}第一次消息为null时,无法执行字符串。这是一个bug。我已经创建了公共类KafkaBroadcasterImpl,并在发送消息之前添加了if(message!=null)。我已经在atmosphereServlet org.atmosphere.cpr.broadcasterClass{packageclasse}.KafkaBroadcasterImpl中编辑了web.xml
bootstrap.servers=localhost:9092
group.id=clinicaleventmanager
zk.connect=localhost:2181
zookeeper.connect=localhost:2181
<servlet>
    <servlet-name>AtmosphereServlet</servlet-name>
    <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
    <async-supported>true</async-supported>
    <init-param>
        <param-name>org.atmosphere.websocket.maxTextMessageSize</param-name>
        <param-value>1048576</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.kafka.propertiesFile</param-name>
        <param-value>WEB-INF/classes/kafka.properties</param-value>
    </init-param>  
    <load-on-startup>2</load-on-startup>
</servlet>
private static final Genson genson = new Genson();

@Override
public DataEntryOperation decode(final String message) {
    try {
        DataEntryOperation dataEntryOperation = genson.deserialize(message, DataEntryOperation.class);
        dataEntryOperation.setDateTime(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
        return dataEntryOperation;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

@Override
public String encode(final DataEntryOperation message) {
    try {
        return genson.serialize(message);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
}