The orchestrator service was failing with the error:
❌ Error publishing to orchestrator-topic: Error: 5 NOT_FOUND: Topic not found
This was happening because:
- Missing Topics: The required Pub/Sub topics didn't exist in the Firebase emulator
- Wrong Connection: Services were trying to connect to production Google Cloud Pub/Sub instead of the local emulator
- Missing Configuration: No automatic emulator detection in the service code
orchestrator-topic(the main one causing the error)category-extraction-topicproduct-extraction-topicproduct-enrichment-topicsustainability-enrichment-topicai-logging-topic
The following services were hardcoded to use production Pub/Sub:
orchestrator-service/pubsub-handler.jsorchestrator-service/index.jscategory-extraction-service/index.jsproduct-extraction-service/index.jslibs/shared/interfaces/cloudProvider.js
Services didn't automatically detect when running in the Firebase emulator environment.
setup-pubsub-topics.js- Creates all required topics and subscriptionstest-pubsub-connection.js- Tests end-to-end Pub/Sub functionalitycleanup-pubsub-topics.js- Removes topics (for cleanup/reset)verify-emulator-config.js- Verifies all services are properly configured
Updated all services to automatically detect emulator environment:
// Auto-detect emulator environment
const isEmulator = process.env.FUNCTIONS_EMULATOR === 'true' || process.env.NODE_ENV === 'development';
const projectId = process.env.FIREBASE_PROJECT_ID || 'your-project-id';
// Initialize Pub/Sub client with emulator support
let pubsub;
if (isEmulator) {
// Use emulator
process.env.PUBSUB_EMULATOR_HOST = 'localhost:8085';
console.log('🔧 Using Pub/Sub emulator at localhost:8085');
pubsub = new PubSub({
projectId: projectId
});
} else {
// Use production
pubsub = new PubSub({
projectId: projectId
});
}All required topics are now created in the Firebase emulator:
- ✅
orchestrator-topic - ✅
category-extraction-topic - ✅
product-extraction-topic - ✅
product-enrichment-topic - ✅
sustainability-enrichment-topic - ✅
ai-logging-topic
Plus corresponding subscriptions for each topic.
orchestrator-service/pubsub-handler.js- Main Pub/Sub handlerorchestrator-service/index.js- Main orchestrator servicecategory-extraction-service/index.js- Category extraction serviceproduct-extraction-service/index.js- Product extraction servicelibs/shared/interfaces/cloudProvider.js- Shared cloud provider interface
setup-pubsub-topics.js- Topic creation scripttest-pubsub-connection.js- Connection testing scriptcleanup-pubsub-topics.js- Cleanup scriptverify-emulator-config.js- Configuration verification scriptPUBSUB_MANAGEMENT.md- Management documentation
cd esg_microservices_platform/firebase-scripts/local
node setup-pubsub-topics.jsnode test-pubsub-connection.jsnode verify-emulator-config.jsnode cleanup-pubsub-topics.js✅ ALL ISSUES RESOLVED
- All required Pub/Sub topics exist
- All services are configured to use the emulator
- End-to-end Pub/Sub communication is working
- Automatic emulator detection is implemented
- Comprehensive management scripts are available
- Restart your orchestrator service - It should now work without errors
- Test the pipeline - The Pub/Sub messaging should work correctly
- Use management scripts - For future setup, testing, or cleanup needs
The automatic emulator detection ensures that:
- Services automatically use the emulator when running locally
- Services automatically use production when deployed
- No manual environment variable configuration is needed
- The same code works in both environments
If you encounter issues again:
- Check emulator status: Ensure Firebase emulator is running with Pub/Sub support
- Verify topics exist: Run
node test-pubsub-connection.js - Check service logs: Look for emulator detection messages
- Recreate topics: Run
node setup-pubsub-topics.jsif needed
- The emulator data is ephemeral and will be lost when the emulator is stopped
- Always test your setup with the test script before running your services
- The automatic detection makes the setup much more robust and user-friendly