Skip to content

Example doesn't work #420

Open
Open
@JaLe29

Description

@JaLe29

Hello nestjs/amqp community,

I would like to integrate this library to my project, but I am having a problem to run example from documentation.

ERROR:

Nest can't resolve dependencies of the CrawlerService (?, AMQP_CONNECTION_PROVIDER_0). Please make sure that the argument AMQP_CONNECTION_PROVIDER_test at index [0] is available in the CrawlerModule context.

Potential solutions:
- If AMQP_CONNECTION_PROVIDER_test is a provider, is it part of the current CrawlerModule?
- If AMQP_CONNECTION_PROVIDER_test is exported from a separate @Module, is that module imported within CrawlerModule?
  @Module({
    imports: [ /* the Module containing AMQP_CONNECTION_PROVIDER_test */ ]
  })

My app.moule.ts

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ENV_DB } from 'const/env';
import { BucketModule } from 'modules/core/bucket/bucket.module';
import { CrawlerModule } from 'modules/core/crawler/crawler.module';
import { ItemsModule } from 'modules/items/items.module';
import { ProvidersModule } from 'modules/providers/providers.module';
import { UsersModule } from 'modules/users/users.module';

import { AmqpModule } from 'nestjs-amqp';
@Module({
	imports: [
		AmqpModule.forRoot({
			username: 'xxxxx',
			password: 'xxxxxx',
			hostname: 'xxxxxx',
			port: 5672,
			protocol: 'amqp',
			name: 'test',
		}), 
	],
})
export class AppModule { }

My crawler.module.ts

@Module({
	imports: [
		AmqpModule.forFeature(), 
	],
	providers: [
		CrawlerService, 
	],
	exports: [CrawlerService],
})

export class CrawlerModule { }

My crawler.service.ts

@Injectable()
export class CrawlerService { 

	constructor(
		@InjectAmqpConnection()
		private readonly amqp: Connection,
	) { }

	async test(message: string) {
		await this.amqp.createChannel((err, channel) => {
			if (err != null) {
				Logger.alert(err, 'TestProvider');
			}
			channel.assertQueue('test_queue_name');
			channel.sendToQueue('test_queue_name', message);
		});
	}

	public async process() {
		await this.test('test') 
	}

}

What is wrong? Looks like I have all steps from example.

Thank you for any help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions