Не удалось выполнить автоподключение. Компоненты типа PubSubTemplate не найдены.JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Не удалось выполнить автоподключение. Компоненты типа PubSubTemplate не найдены.

Сообщение Anonymous »

введите здесь описание изображения
Здесь я использовал адаптер входящего канала pubsub для отправки и получения сообщения от издателя и подписчика. Этот код взят только из документации Google Cloud pubsub, здесь установлены все необходимые зависимости, а все остальное в порядке.
Здесь ниже я привожу код класса inboundConfiguration

Код: Выделить всё

import com.google.cloud.spring.pubsub.core.PubSubTemplate;
import com.google.cloud.spring.pubsub.integration.AckMode;
import com.google.cloud.spring.pubsub.integration.inbound.PubSubInboundChannelAdapter;
import com.google.cloud.spring.pubsub.support.BasicAcknowledgeablePubsubMessage;
import com.google.cloud.spring.pubsub.support.GcpPubSubHeaders;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.mediumpubsub.config.pubsubConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;

import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandler;

@Configuration
@RequiredArgsConstructor
@Slf4j
public class inboundConfiguration {
private final pubsubConfiguration pubsubConfiguration;

@Bean
public PubSubInboundChannelAdapter messageChannelAdapter(
@Qualifier("pubsubInputChannel") MessageChannel inputChannel,PubSubTemplate pubSubTemplate) {
PubSubInboundChannelAdapter adapter =
new PubSubInboundChannelAdapter(pubSubTemplate, pubsubConfiguration.getSubscription());
adapter.setOutputChannel(inputChannel);
adapter.setAckMode(AckMode.MANUAL);

return adapter;
}

@Bean
public MessageChannel pubsubInputChannel() {
return new DirectChannel();
}

@Bean
@ServiceActivator(inputChannel = "pubsubInputChannel")
public MessageHandler messageReceiver() {
return message -> {
log.info("Message arrived! Payload: "  + new String((byte[]) message.getPayload()));
BasicAcknowledgeablePubsubMessage originalMessage =
message.getHeaders().get(GcpPubSubHeaders.ORIGINAL_MESSAGE, BasicAcknowledgeablePubsubMessage.class);
originalMessage.ack();
};
}
}
это исходящая конфигурация для справки

Код: Выделить всё

package org.example.mediumpubsub.outbound;

import com.google.cloud.spring.pubsub.core.PubSubTemplate;
import com.google.cloud.spring.pubsub.integration.outbound.PubSubMessageHandler;
import org.example.mediumpubsub.config.pubsubConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.MessageHandler;

public class outboundConfiguration {
private final pubsubConfiguration pubsubConfiguration;

public outboundConfiguration(org.example.mediumpubsub.config.pubsubConfiguration pubsubConfiguration) {
this.pubsubConfiguration = pubsubConfiguration;
}

@Bean
@ServiceActivator(inputChannel = "pubsubOutputChannel")
public MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
return new PubSubMessageHandler(pubsubTemplate, pubsubConfiguration.getTopic());
}

@MessagingGateway(defaultRequestChannel = "pubsubOutputChannel")
public interface PubsubOutboundGateway {

void sendToPubsub(String text);
}
}

а также контроллер исходящего трафика

Код: Выделить всё

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/send")
@RequiredArgsConstructor
@Slf4j
public class outboundController {
private outboundConfiguration.PubsubOutboundGateway messagingGateway;
@PostMapping("/pubsub")
public void sendMessage(@RequestParam("message") String message) {
log.info(message);
messagingGateway.sendToPubsub(message);
}
}
Мне очень нужно решение этой проблемы, связанной с pubSubTemplate, потому что во всех других видеороликах YouTube по этому поводу эта ошибка не возникает

Подробнее здесь: https://stackoverflow.com/questions/790 ... type-found
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»