Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example doesn't work #420

Open
JaLe29 opened this issue Jan 26, 2021 · 0 comments
Open

Example doesn't work #420

JaLe29 opened this issue Jan 26, 2021 · 0 comments

Comments

@JaLe29
Copy link

JaLe29 commented Jan 26, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant